I asked this on answers, but no one seems to know:
http://answers.unity3d.com/questions/774857/hideflagsdontsave-onenable-and-play-mode.html
I create some objects in the editor that have HideFlags.DontSave set. When I go into play mode, OnEnable in the scripts for those objects is being called, but the objects aren’t actually saved. I know they aren’t saved because once I can see the play mode hierarchy, those objects aren’t there.
Why is OnEnable being called?
How is OnEnable related to being saved?
I would expect that objects that aren’t saved wouldn’t have onEnable called when play mode starts.
You can always test which hideflag your object has on the OnEnable method.
The problem isn’t that the hide flag isn’t being set correctly, it’s that when it is set to DontSave (and the objects aren’t being saved, they don’t show up in the hierarchy after play mode starts) onEnable is called at some point between when play is press, or code is compiled, and the rest of the objects are reloaded.
How is that a problem?
private void OnEnable()
{
if (hideFlags == HideFlags.DontSave)
return;
//blah
}
Then none of these particular objects would ever have their onEnable run. They are set to DontSave immediately after being created.