I have had several cases come up where I want to have complex data on a MonoBehavior class that should be saved but I cannot seem to find a way to do this.
Simple Example
public class DataClass : ScriptableObject
{
public string mValue1;
public int mValue2;
}
public class BehaviorClass : MonoBehavior
{
[SerializeField]
public DataClass mData;
public BehaviorClass()
{
mData = ScriptableObject.CreateInstance<DataClass>();
}
}
The mData object reference gets lost any time you exit the edior and come back or any time you run the game in the editor. The mData field simply will not serialize on its own. Is there a way to FORCE this to happen? Like some kind of OnSerialize() routine I can implement?