Custom abstract class (and inheritance) not allowing public array despite having System.Serializable?

Hey all,

I’ve searched similar posts, but must be missing something as I’m not getting the desired result.

Basically, playing around with basic AI to get understanding down. Have a base class as follows:

[System.Serializable]
public abstract class ActionBaseClass {

    public abstract void SetupAction(StateHandler stateHandler);
    public abstract bool AbleToPerformCheck();
    public abstract bool PerformAction();

}

I then have a ‘concrete’ class that inherits from this:

[System.Serializable]
public class Action_MoveTo : ActionBaseClass {

    StateHandler ourHandler;

...

And finally a controller that SHOULD hold an array of the available actions to it - as follows:

public class StateHandler : MonoBehaviour {

    [SerializeField] // I have tried it with this line missing as well.
    public ActionBaseClass currentAction;
    [SerializeField] // I have tried it with this line missing as well.
    public ActionBaseClass[] actions;

...

However when the scripts are compiled I am NOT seeing a public array or single variable in the inspector…
97936-bugcap.png

As stated I have tried it with both “[SerializeField]” lines missing - however I’m still getting the same results. Any help would be gratefully appreciated.

Many thanks!

Unity does not support inheritance when it comes to custom serializable classes. The serialization system does not serialize the actual instance but only the fields as “sub-fields”. However it always uses the type of the variable and not the type of the instance that might be referenced. Since your variable type is “ActionBaseClass” it only serializes fields which are defined in that class.

If you need inheritance you have to use either MonoBehaviour or ScriptableObject derived classes.

For more information read the Script Serialization page carefully