Is it possible to work with scriptable objects (SO) as if they behaved like any other assets? In other words I’d like to:
- Create them (preferably from menu).
- Be persistent between Unity restarts (not turning into empty assets after each Unity restart).
- The modifications of SO particular instances to be also persistent (if possible).
- The references of the SO’s in monobehaviours (MB) to be persistent instead of losing them and have null references after Unity restart.
What’s the minimum scripting I’d have to do to achieve this?
So far I’ve tried:
- [CreateAssetMenu] It creates the asset in Project. I drag the asset into a reference of some MB in Inspector but this doesn’t do anything about persistence of the SO’s themselves, nor of the references to them in MB’s.
- Putting:
UnityEditor.AssetDatabase.Refresh();
UnityEditor.EditorUtility.SetDirty(this);
MonoBehaviour.print(this);
UnityEditor.AssetDatabase.SaveAssets();
into each SO’s Awake() still not solving persistence of any kind.
I’ve even had a Unity crash when I put the code in OnEnable().