ValueDropdown with custom objects disappear after saving script

Issue #915 invalid
Aleix Cots created an issue

I am not certain if this is an issue or I just haven't figured it out how to do that yet, but I've tried all the combinations I’ve found.

1.What happened?

If I use the attribute ValueDropdown with a list of interface or abstract (the values are custom objects inheriting from the abstract class or the interface), when I reload Unity (some change in script and save it) the list will lose all the objects.

2.How can we reproduce it?

I have the following structure: interface IAction, abstract class BaseAction, and a normal class Jump. Jump inherits from BaseAction, and BaseAction implements IAction.

I have a MonoBehaviour with a public list of IAction or BaseAction with a ValueDropdown attribute and I can add to the list an object of Jump through the inspector, but when I change something in any script and save, after Unity reloading the list will lose all the objects.

It seems to dislike interfaces and abstract classes for this purpose, because this happens when the first field of the list element in the inspector is not a field of this specific class but instead: *DerivedType: Interface/BaseType (see picture attached).

3.If screenshots would help explain or demonstrate your issue, please include these.

  • MonoBehaviour (Same lines with interface or abstract class, just comment/discomment).
  • Picture of how it is shown in inspector after adding Jump (when List<BaseAction>).
using Sirenix.OdinInspector;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

[ShowOdinSerializedPropertiesInInspector]
public class CharacterLocomotion : MonoBehaviour
{
    [ValueDropdown("GetAvailableActions", IsUniqueList = true, DrawDropdownForListElements = false, ExcludeExistingValuesInList = true)]
    public List<IAction> _actionList = new();
    //public List<BaseAction> _actionList = new();

    private ValueDropdownList<IAction> GetAvailableActions()
    //private ValueDropdownList<BaseAction> GetAvailableActions()
    {
        return new ValueDropdownList<IAction>() { new Jump() };
        //return new ValueDropdownList<BaseAction>() { new Jump() };
    }
}

4.What version of Unity are you using?

2021.3.14f1

5.What version of Odin are you using? (See "Tools > Odin Inspector > About")

3.1.10.0 (I just downloaded the last version at this moment 19/03/2023)

6.Do you have Editor Only mode enabled?

No, as far as I know… I did not enabled anything even related.

7.What operating system are you on?

Win10

Thanks!

Comments (3)

  1. Antonio Rafael Antunes Miranda

    That looks like a serialization issue. I see that you have the ShowOdinSerializedPropertiesInInspector attribute applied to the class, so you probably meant to inherit from SerializedMonoBehaviour, which should fix your issue. Alternatively, you could also use the SerializeReference attribute instead.

  2. Log in to comment