ScriptableObject lifetime and BuildPlayer

It seems that BuildPlayer unloads all ScriptableObject instances from memory during/after a build - I get OnDisable/OnDestroy calls on my objects.

However, it doesn’t appear to reload them afterwards - I don’t get any OnEnable() call.

Is there any way to get my object to survive this process? I’ve tried calling DontDestroyOnLoad() and it doesn’t seem to have helped; I’ve also tried setting HideFlags to None just in case but that also hasn’t helped.

Note that my instance is not associated with an asset - I guess I could create one temporarily but I’d prefer to avoid it if at all possible…

(This is in Unity 4.2.0b2 - if the behaviour is different in newer versions, let me know…)

Confirmed (in 4.3.0b6) that this happens to ScriptableObject instances that aren’t persisted to disk. Ones that are backed by an asset file get reloaded, but ones that aren’t do not.

Filed as bug #572112. I’m half expecting the answer to be “this is by design” but at least then someone will have actually said that :slight_smile:

Wasn´t there something like HideFlags.HideAndDontSave supposed to prevent exactly this behaviour?

Wouldn’t HideAndDontSave do the opposite of what I want, though?

I thought that this must be set in your situation, based upon this megathread: http://forum.unity3d.com/threads/155352-Serialization-Best-Practices-Megapost

But maybe I misunderstood the rooted part of the article, sorry if this was the case.

Ah! You may be absolutely right. I’ll try it out…

Edit: Yep, you’re right! So that’s how to solve this. Cheers :slight_smile: