'One-time loaded assembly' problem in editor, static variable value resides

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,

  1. class A’s OnStart() → CurrentLoadedScenesAlias = new List();
  2. class B’s OnEnable() → call A’s SwitchScene() method
  3. 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?

We don’t reload assemblies on play mode because it’s super fast in Flax. That’s why you have to wait few seconds to start play mode in Unity.

Instead, in Flax we have GamePlugins which have proper lifetime in both Editor PlayMode and cooked Game: Plugins | Flax Documentation

The problem is that static instance is acting different between first run(after compile) and second+ runs.

  1. Adding a static class ‘Core’ in assembly
  2. Attach actors configured in editor when initializing :
public static class Core
{
    public static Scenes    Scenes; 

    static Core()
    {
        Actor g = Level.FindActor("--Core--");
        Scenes = g.GetScript<Scenes>();
    }
}
  1. Call static instance’s method by Engine -binded script :
public class Bootstrap : Script
{
    public static IEnumerator<Wait> BootstrapByFrames()
    {        
        Core.Scenes.SwitchScene();
    }
}
  1. Initialize Actor instance by method :
public class Scenes : Script
{
    private Actor _loadingScreen;

    void SwitchScene()
    {
           _loadingScreen = PrefabManager.SpawnPrefab(LoadingScreenPrefab); 
    }
}

At first run in editor, all execution works fine.
This is the Actor variable which will hold the initialized instance, seen in watch window :
image

But from the second run, member _loadingScreen is not properly destroy/initialized.
Before all initialization or bootstrapping, static instance still has undestroyed data.


which makes ‘initial assumption’ more difficult while developing in engine editor.