I’ve recently been looking at scriptable objects as a new tool to build my game, and I’ve recreated a set of classes that can hold variables and references for different data types that can be dropped into and shared between objects in my scene as required. Now, I’m aware that if I alter a scriptable object at runtime whilst I run it in the editor, it will actually save into the .asset file, meaning that it would also persist across scenes. I’m also aware that it will not do this at runtime in the build as it cannot serialise the data back into the .asset file outside of the editor. My question is, if I reference the .asset file in 2 different scenes and change it in one scene, will it keep the value when I load the other scene (i.e. will it keep the value in memory for the duration of the session within the build, or will it reload it from the .asset file when I switch scenes)?
Answering here because it’s the first hit on google.
Found the solution to not unload scriptable objects between scenes, even if they are not referenced in one scene (http://answers.unity.com/comments/1569389/view.html ). Add the following snippet of code to you SO:
private void OnEnable() => hideFlags = HideFlags.DontUnloadUnusedAsset;
Changed values will stay for a whole application runtime as long as you not null all references in current scene and unload SO with