SerializedField variables in child classes


So, I decided to do a spin action slightly in a different way, and it plays an animation. I set up everything correctly, but from the point where we make a parent class, it end up that both SpinAction and MoveAction have a [SerializeField] private Animator variable. I thought it would be great to include this one in the parent class as well, but I get an error saying “The same field name is serialized multiple times in the class or its parent class. This is not supported: Base(MonoBehaviour) animator”. Which way is the best to implement inheritance with SerializeFields?


There are a couple of possibilities here…
First, make sure that you don’t have the SerializedField in both the BaseAction and one of the Spin or MoveAction. This will cause a direct serialization error.
Make sure that the variable in the Base class is protected, no private.

[SerializeField] protected Animator animator;

once again, remove any [SerializeField] Animator animator in the base classes.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms