Search code examples
c#unity-game-engineserializationabstract-class

SerializeField in abstract class not appearing in inspector


I'm running into what I think is probably a syntax issue. I have an abstract class:

public abstract class MyAbstractClass : MonoBehavior {
    public abstract GameObject ShouldBeSerialized { get; set; }
}

that has a property that I want to appear in the inspector for concrete class instances:

public class MyConcreteClass : MyAbstractClass {
    [SerializeField] public override GameObject ShouldBeSerialized { get; set; }
}

I've tried adding [SerializeField] to both the concrate and abstract definitions. I've tried adding [Serializable] to the abstract class definition. I've tried making the property both virtual and non-abstract in the abstract class definition. Perhaps there's a combination of the above that I've missed?


Solution

  • Use [field: SerializeField] instead of [SerializeField]

    [field: SerializeField] public override GameObject ShouldBeSerialized { get; set; }