Search Unity

[SOLVED] Editor / Build iterating through lots of copies of scene to load after "LoadSceneAsync"

Discussion in 'Editor & General Support' started by Mr_Orange, Dec 10, 2016.

  1. Mr_Orange

    Mr_Orange

    Joined:
    Jan 8, 2015
    Posts:
    5
    Hello there,

    I did search online for something similar to my problem, but all I found was non-related stuff. Might be possible that is has already been answered once but my search terms didn't gimme any results.

    Here is the Deal:

    I have several scenes (older versions, whenever I change a lot in a scene I tend to save it as a new one with another Version number concatenated) - in the end there will be no more than 3.

    So in my first scene there is a script which calls:

    Code (CSharp):
    1.     public void changeScene()
    2.     {
    3.         //SceneManager.LoadSceneAsync("FirstRoom_v28");
    4.         SceneManager.LoadSceneAsync(1);
    5.  
    6.     }
    As you can see I tried to change the selection from scene name to index within the Build settings. Didn't change anything.

    After that I removed all other scenes in the folder so that only the two essential scenes remain.

    Still the phenomenon occurs., which is:

    After the new scene was completed loaded, both the Editor and the Build iterate through a lot of "disabled copies" of the scene that was just loaded. After Unity went through all of them it realizes noting more to do and only then I am finally at the point where I wish to be right from the start after loading the scene.

    I attach two screenshots to show you what I mean. First one is taken right after scene change and the next one shortly before Unity finished the described process.

    Any input is welcome!

    Thanks

    - O
     

    Attached Files:

  2. Mr_Orange

    Mr_Orange

    Joined:
    Jan 8, 2015
    Posts:
    5
    So, to answer this question:

    The described behaviour happens if the code where "SceneManager.LoadSceneAsync(1);" is located gets called more than once.

    To avoid this, make sure that this code is REALLY only called once.

    Easy to achieve using a bool variable:

    Code (csharp):
    1.  
    2.   public void ChangeScene()
    3.   {
    4.   if (!loadingStarted)
    5.   {
    6.   loadingStarted = true;
    7.   //SceneManager.LoadSceneAsync("FirstRoom_v28");
    8.   SceneManager.LoadSceneAsync(1);
    9.   }
    10.  
    11.   }
    12.  
    Cheerz!