sschmid / Entitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MIT License
7.11k stars 1.11k forks source link

There is no observers , if deactivate "Reload domain" in Project Settings -> Editor #999

Closed Sergan4ik closed 2 years ago

Sergan4ik commented 2 years ago

Hi,

I found a bug, when you replay game in editor without "Reload Domain" option , there is no context observers in DontDestroyOnLoad

Inspector, after reload domain (any change in code) image

Inspector, if code the same, but starts game once more time image

If create observers manually, entities is duping , and can't collapse observers in inspector First time: image Second: image Third: image

etc

DeusExMachina1993 commented 2 years ago

Resetting Context in Start Worked for me.

_contexts = Contexts.sharedInstance;
_contexts.Reset();

another solution is creating a new Context in Start

sschmid commented 2 years ago

potential duplicate #967

eterlan commented 1 year ago

The reason is because turn off"Reload domain" would not reset those static fields. Add this code somewhere should fix this problem.

    [InitializeOnEnterPlayMode]
    public static void ReloadContext()
    {
        Contexts.sharedInstance = null;
    }

or @sschmid have time to modify generator generate this one in context. I would like to help but have no idea howto..