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!!!