Serializing list of base and derived classes with custom inspector

Hi everyone!

I have a problem trying to save an array of a list of custom base and derived classes. I have tried to follow the Serialization Megapost but I am still unable to save the data within the array of lists.

GameConfigManager:

public class GameConfigManager : MonoBehaviour
{
	public MultidimensionalCategoryGame[] categoryGameList;
	public int playsToUnlock;
}

MultidimensionalCategoryGame.cs

[System.Serializable]
public class MultidimensionalCategoryGame : ScriptableObject
{
	[SerializeField]
	public List<Powerup> array;
	
	public void OnEnable()
	{
		hideFlags = HideFlags.HideAndDontSave;
		if (array == null)
		{
			array = new List<Powerup>();
		}
	}
}

CategoryGame.cs

[System.Serializable]
public class CategoryGame : Powerup
{
	public int discount;
	public string[] instructions;
	
	public override void OnEnable()
	{
		base.OnEnable();
		
		if (instructions == null)
		{
			discount = 0;
			instructions = new string[0];
		}
	}
}

Powerup.cs

[System.Serializable]
public class Powerup : ScriptableObject
{
	public string name;
	public string description;
	public float cost;
	
	public virtual void OnEnable()
	{
		hideFlags = HideFlags.HideAndDontSave;
		
		if (name == null)
		{
			name = "";
			description = "";
			cost = 0;
		}
	}

From my testing, I can save the integer playsToUnlock variable within GameConfigManager. I can also enter data for the MultidimensionalCategoryGame objects in the inspector, but when I hit play my data within MultidimensionalCategoryGame objects are not saved.

Sorry for the long post! Thanks for your time and please help!!!

Not sure if this is going to help you out; but Jacob Pennock wrote a nice post on how to create custom assets.

This will provide you with the means to do offline editing on your powerup and drag that powerup straight into your inspector.

http://www.jacobpennock.com/Blog/?p=670

If this doesn’t help out, let me know and I’ll dig a bit deeper into your code