Entitas icon indicating copy to clipboard operation
Entitas copied to clipboard

Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?) The following scene GameObjects were found: <unnamed>)

Open huannguyenv opened this issue 6 years ago • 6 comments

Hi,

I have a problem while using ITeardownSystem

`

void Awake()
{
    m_StartSceneSystem = new StartSceneSystems(Contexts.sharedInstance);
    m_StartSceneSystem.Initialize();
}

// Update is called once per frame
void Update()
{
    m_StartSceneSystem.Execute();
    m_StartSceneSystem.Cleanup();
}

private void OnDestroy()
{
    m_StartSceneSystem.DeactivateReactiveSystems();
    m_StartSceneSystem.TearDown();
}

When I change to new Scene unity throw me an error that

Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?) The following scene GameObjects were found: unnamed)

If I have 5 entities on current scene so I will have 5 unnamed in that error! And then if I disable Teardown the error will disappear so I guest TearDown is reason.

Please help me with this error, thank you so much!

huannguyenv avatar Mar 26 '19 10:03 huannguyenv

can you provide more source code? why you need to call Initialize() execute() cleanup() and teardown() on Monobehavior?

vanlecs09 avatar Mar 26 '19 15:03 vanlecs09

Seems strange to be controlling one individual system from a monobehaviour like that - have you looked at the GameController.cs in match-one? Look at GameSystems too.

FNGgames avatar Mar 26 '19 17:03 FNGgames

Guess it caused by unity visual debug

ntl92bk avatar Mar 26 '19 17:03 ntl92bk

What does your Teardown system do? Can you post a minimal project that reproduces this?

akoolenbourke avatar Mar 28 '19 09:03 akoolenbourke

Sorry, I don't have computer couple days ago so I can't reply this thread. I try to build my game to android phone and use adb log for debug but this error not show off so I think it is bug of unity visual debug. Btw, my Teardown system use for destroy all exist entities before changing scene, this is my code for this

public class TeardownGameEntity : ITearDownSystem
{
    private Contexts m_Contexts;

    public TeardownGameEntity(Contexts _Contexts)
    {
        m_Contexts = _Contexts;

    }

    public void TearDown()
    {
        m_Contexts.game.DestroyAllEntities();
        
    }

}

Thank you for all of your supports and sorry for late reply

huannguyenv avatar Mar 29 '19 03:03 huannguyenv

I use Context.sharedInstance in OnDestroy() method. That's the reason for my bug. See more http://robamemo.hatenablog.com/entry/2018/01/11/195311

PhamAn12 avatar Jun 28 '19 03:06 PhamAn12