Serialising subclass variables in inspector

Is it possible to serialise the variables in a subclass in the inspector (In list)?

At the moment I have a sub class, a base class, and a “class manager” that has a list of type baseclass.
In runtime it adds classes of type subclass into the list of baseclass.
But when the classes are added to the list and updates the inspector, it looks like the inspector only shows the baseclass variables, and none of the subclass’ variables.
For the most part it looks like the list supports subclasses, and I can call subclass functions and whatnot, but the inspector still doesn’t serialise the subclass variables?

Is there a fix for this? Or should I find a different solution for having a list of different subclasses?


BaseClass.cs :

using UnityEngine;
using System.Collections;

public class BaseClass {

	public string name;

	public int baseInt;

	public float baseFloat;
	public virtual void TestFunction(float flt)
		baseFloat -= flt;
		Debug.Log("TestFunction baseclass called.");


using UnityEngine;
using System.Collections;

public class SubClass : BaseClass {

	public float subFloat;

	public override void TestFunction(float flt) {


using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ClassManager : MonoBehaviour {

	public List<BaseClass> classList = new List<BaseClass>();

	BaseClass currentClass;

	public void Button() {
		BaseClass wow = new SubClass();
		currentClass = classList[0];

	public void OtherButton() {

	public void AddClassToList(BaseClass bs) {

	public void RemoveClassFromList(BaseClass bs) {

No, Unity doesn’t support inheritance for custom serializable classes. Only classes derived from UnityEngine.Object support inheritance when it comes to serialization in Unity. The only classes you can actually use as base class are MonoBehaviour (which always have to be attached to a gameobject) or ScriptableObject.

Unity serializes custom serializable classes based on the variable type. So no matter what actual instance the variable references it will always be serialized as base class.

Since Unity 2019.3 there’s an update:

Kernel: Introducing new serialization attribute: SerializeReference

Unity now has the SerializeReference attribute which adds some new features to the serialization system and allows custom serializable classes to be serialized “as reference”. However those references are still local to the housing object. So they are serialized alongside with the housing object. Though such fields now support inheritance and the type of the instance is no longer determined by the field type but the actual type.

This adds makes it more versatile, but at the same time the inspector will no longer create those classes for you since even “null” is now supported. As I mentioned above those references can’t span across multiple components or scriptable objects. Those can only reference other custom serializable classes that Unity’s serialization system supports.

As you can read in the documentation such fields now also support interfaces or abstract types (since they are no longer bound to their field type)

The above answer is out of date with the introduction of the SerializeReference decorator. Adding this decorator to the above code will now produce the desired outcome:

[SerializeReference] public List classList = new List();