TextusGames / UnitySerializedReferenceUI

The UI for Unity's SerealizedReference attribute. It allows to change the instance type of field right in editor.
MIT License
144 stars 22 forks source link

Lists of abstract classes do not work. #11

Closed pudy248 closed 2 years ago

pudy248 commented 2 years ago

Notably, abstract classes on their own, and lists of interfaces both work, but lists of abstract classes in particular are ineffective. Arrays also don't work. Sample code to demonstrate the issue:


public class ReferenceTestClass: MonoBehaviour
{
    [SerializeReference]
    [SerializeReferenceButton]
    public Test1 singleClassTest; //Works fine
    [SerializeReference]
    [SerializeReferenceButton]
    public List<Test1> listTest = new List<Test1>(); //Does not show up in the editor at all
    [SerializeReference]
    [SerializeReferenceButton]
    public List<Test1> listTest; //Not instantiating the list has no effect
}

public abstract class Test1
{
    public int field1;
}

public class Test2: Test1
{
    public int field2;
}
pudy248 commented 2 years ago

Turns out I'm actually retarded and adding a constructor and the [System.Serializable] attribute to each class makes things work fine.