Have there been any known issues persisting ScriptableObjects via a scene at runtime in Unity 5.6.3? This used to work just fine, and I’m not sure if anything has changed in this regard. In my scene, during runtime, I am loading a scriptableobject, editing it, and then cycling through more scriptableobjects, and editing. That should have been enough to persist them. I’m losing some changes in some cases. Any ideas?
EDIT:
One thing I should mention is that I’m also using Selection.activeObject. I saw a note in the docs that says Selection.activeTransform is recommended, but if I’m setting Selection.activeObject to a ScriptableObject, I can’t use activeTransform in this case.
The second one. I am running the game in the editor, and loading and modifying the SO. Once I stop running the game, some of the SOs that I modified are not actually modified.
EDIT:
Also, I am sure all of the SOs that I am editing are not marked as readonly.
Unless you’re actually setting the SO as dirty and using AssetDatabase.SaveAssets, I believe the only thing you’re changing in playmode is the cached serialized copy of the ScriptableObject and not the physical file. Since they’re just like any other YAML files on the disk, you need to actually save them back to that file or changes will be lost when you exit play mode. It’s possible some of the operations you’re performing are triggering this process, and others are not.
I’ve actually never even tried saving an SO in playmode (seems a bit odd to me), so don’t take this as gospel.
I think you’ll have to mark them as dirty and/or use SaveAssets:
When you go into play mode in the editor and then stop, a lot of things happen. For instance unity saves a cache of the scene when you press play and then reverts back to that version when you exit play. This is why when you play in the scene, those changes to stay.
ScriptableObjects, and other assets, technically aren’t part of the scene so they aren’t effected directly by that. But there is other things that happen… for instance unity sometimes reloads all of memory between playing/stopping a scene. And since those ScriptableObjects are in memory, they may get purged. If they weren’t saved they get reverted back to whatever is on disk.
Okay, thanks. I thought I was already doing SetDirty(), SaveAssets() since my code hasn’t changed for the year+ that I’ve been using it. I was under the assumption at the time that modifying SOs in runtime were guaranteed to be persisted and not reverted, but for whatever reason, upgrading to 5.6.3 made the issue show up. Calling SetDirty() and SaveAssets() did the trick!
Thanks @DonLoquacious . The specifc use case is that the “game” is an editing tool for the main game. It’s a tile editor that has specific mouse camera navigation controls that are more suited to the task than modifying the behavior through the Unity editor directly. It makes editing my SO data much quicker.