Property Editor - List with inheritance


I have a monobehaviour that contains this:

public class UIAnimator : MonoBehaviour
	public List<BaseUIAnimation> Animations;

And BaseUIAnimation is basically a normal serializable class:

public class BaseUIAnimation

There are multiple classes inheriting from BaseUIAnimation.

The problem lies when I want to edit a GameObject with the UIAnimator script. I want to be able to add a new item in the Animations field, of different types (all inheriting BaseUIAnimation of course), and see the properties of that specific inherited class.

At the moment, when I add a new item to the list, the item is of type BaseUIAnimation and therefor completely empty.

What is the best way to implement what I want? I basically want a way to switch the type of an item in the list (and then I imagine the properties are gonna be shown correctly?)


Since your BaseUIAnimation class is a normal custom class it won’t work that way since Unity doesn’t support inherintance for custom classes.

The easiest way is to derive your BaseUIAnimation class from MonoBehaviour and attach the derived classes either to the same GameObject or a child GameObject and reference them from your List. This will work as the actual type is serialized by Unity since it’s a type Unity can actually serialize.