I've created a ScriptableObject class MySO
that gets modified in its Awake()
function. I also added EditorUtility.SetDirty(this);
as its last command. The class has a List<someOtherClass> myList
field. During the Awake
function, I add a couple instances to this list.
When creating a new instance of MySO
through the AssetMenu, at first, it seems to display the populated list correctly in the Inspector (basically Awake()
executes fine), but the list empties the moment I click anywhere or press Enter. It's only after restarting Unity that the changes show up.
Everything relevant is either public
or [Serializable]
.
[CreateAssetMenu(fileName = "NewMySO", menuName = "MySO")]
[System.Serializable]
public class MySO : ScriptableObject
{
public List<someOtherClass> someOtherClassList;
private void Awake()
{
//-------------------------
//add instances to someOtherClassList
//--------------
EditorUtility.SetDirty(this);
//AssetDatabase.SaveAssets(); //Didn't help
//AssetDatabase.Refresh(); // Didn't help
}
}
I've tried adding AssetDatabase.SaveAssets()
and AssetDatabase.Refresh()
too after SetDirty(this)
. Neither work, and the first one leads to errors due to restrictions during asset importing
when restarting Unity.
Any help'd be appreciated.