I added some bootstrap code in OnEnabled(), but it works only first run inside editor after modifying and rebuilding source code. Like Unity, game assembly is loaded once and re-executed every time when clicking ‘Play In Editor’ button. The problem is, assembly instance is already loaded and not cleared & reinvoking OnStart/OnEnabled works not reinitializes all.
i.e, by Debugger in 2nd run,
- class A’s OnStart() → CurrentLoadedScenesAlias = new List();
- class B’s OnEnable() → call A’s SwitchScene() method
- class A’s SwitchScene() → if (CurrentLoadedScenesAlias.Contains(Alias)) return;
called in order.
Interestingly, after 1st run List ‘CurrentLoadedScenesAlias’ is already allocated and has values, [1] does not clear the list and [3] cannot work as intended.
OnStart() and OnEnable() members both does not clear static instance of classes A&B.
I think independant run of compiled game will start from fresh memory, but in editor assembly memory is messed up. Is there any way to ‘Run cleared’ in editor even having static variables?