Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug SceneLoading Tests: Levels wont unload and grey out instead.

Discussion in 'Testing & Automation' started by mikeNspired, Apr 25, 2019.

  1. mikeNspired


    Jan 13, 2016
    I have alot of additive scenes in the project I am working on.

    In my playmode tests. I load a list of new scenes and then unload the old list of scenes.

    My test checks SceneManager.sceneCount. My problem is for certain tests the levels only get deactivated when I unload them. SceneManager.SceneCount counts deactived levels also. They turn grey and say "is Loading".

    How can I get these levels to completely unload? Whats weird is sometimes unloading levels will work.

    I have tried Async Unload in the method, and I have the same problem.

    If I cannot get the levels to unload, is there a way to check what scenes are activated vs the deactivated scenes?
    Last edited: May 6, 2019
  2. liortal


    Oct 17, 2012
    Do you have an example of what kind of tests are you creating?
    In our project, we have 1 main scene, where the rest of the game's UI and other screens are dynamically loaded additively.

    To test stuff, we create tests that register on the sceneLoaded event, and block until that happens.
    Consequently, when the test completes we wait for the sceneUnloaded event to happen, to know that the scene unloaded successfully.
  3. mikeNspired


    Jan 13, 2016
    I thought I fixed the problem....but I did not.
    My tests simply have something like

    Code (CSharp):
    2. SceneLoader.UnloadLevel();
    3. while(!isUnloadComplete) yield return null;
    4. if(!SceneManager.GetSceneByName("Environment2).IsValid()) Assert.Fail()
    But my tests fail from getting stuck in a while loop like the one below

    Code (CSharp):
    1. SceneManager.UnloadScene("Environment2");
    2. While(SceneManager.GetSceneByName("Environment2").IsValid()){
    3. Debug.Log("Trying to Unload");
    4. yield return null;
    5. }
    Ive tried AsyncUnload, ive also tried calling unload over and over inside the while loop.

    The level unloads but remains in the heirachy as a greyed out level named
    Environment2 (is loading)
    Even if I put the test time to 60 seconds, I just gets stuck in the whileloop with the level greyed out.
    Sometimes if I pause the test and click play again it will fully remove the level.