Search Unity

LoadSceneAsync never works?!

Discussion in 'Scripting' started by Jbaker08, May 3, 2017.

  1. Jbaker08

    Jbaker08

    Joined:
    Oct 8, 2012
    Posts:
    52
    Hi,
    I have a small scene that waits for the player to enter a lift. Once the player is in the lift I want it to unload the first scene and additively load a new one.
    Problem is my scenes just never load? In editor and in build. Tested for both. I even tested with a scene that is basically empty. It says 'isloading' in the hierarchy but never actually activates.

    If I use LoadScene without a AsyncOperation, it loads instantly but there is a small hitch I do not want.
    What on earth am I doing wrong here? Using Unity 5.6f4.

    To start the coroutine
    Code (CSharp):
    1.     public void Load_Hotel_Wrapper()
    2.     {
    3.         StartCoroutine(Load_Hotel_Scene());
    4.     }
    5.  
    To load the scene
    Code (CSharp):
    1.     IEnumerator Load_Hotel_Scene()
    2.     {
    3.         Current_Player_State = PlayerStates.Hotel;
    4.  
    5.         //set camera effects for WWII Scene
    6.  
    7.        
    8.         AsyncOperation AO = SceneManager.LoadSceneAsync("Final_Scenes/Hotel_Scene", LoadSceneMode.Additive);
    9.      
    10.         AO.allowSceneActivation = false;
    11.        
    12.         while (AO.progress < 0.9f)
    13.          {
    14.              yield return null;
    15.         }
    16.  
    17.  
    18.         Debug.Log("complete loading");
    19.         //Fade the loading screen out here
    20.         Loading_New_Scene_Complete = true;
    21.         //Fade the loading screen out here
    22.         AO.allowSceneActivation = true;
    23.  
    24.         yield return new WaitForEndOfFrame();
    25.  
    26.         Loading_New_Scene_Complete = false;
    27.     }

     
  2. Kwinten

    Kwinten

    Joined:
    Jan 25, 2015
    Posts:
    49
    I'm not exactly sure what's happening, but I have a question for you: why are you loading a scene additively after unloading the previous scene? Additive means "add this scene to another scene, while keeping the other scene active as well". If there is no other scene active, I'm not sure how additive loading behaves. Could you use Single loading mode instead?

    Also, small tip:
    Code (CSharp):
    1. yield return AO;
    No need to use a while loop and check for progress constantly. The above will also simply wait for the loading to be done.
     
    dukenukem4d likes this.
  3. Jbaker08

    Jbaker08

    Joined:
    Oct 8, 2012
    Posts:
    52
    I tried your tips, It still seems to never load? Even on scenemode.single.
    Really bizarre and frustrating since it's stopping me from developing a scene.
     
  4. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    Have you tried commenting out the allowSceneActivation lines to see if that's what's blocking you?

    Also, how are you organizing your scenes? If you load multiple scenes, you also must activate them in the same order. A scene will be blocked if you've loaded another scene but haven't activated it.
     
  5. Jbaker08

    Jbaker08

    Joined:
    Oct 8, 2012
    Posts:
    52
    Okay so I built a pretty much empty scene with just a cube, tried loading it in my current scene. Doesn't load.
    Created a completely empty scene and tried to load the scene with the cube. It worked. So then I tried my big scene inside the blank scene and it also worked however it actually took around 3-4 minutes to load the scene..
    It's not particularly big scene or anything. Is Unitys loading just absolutely terrible or something?!

    I have an error coming up in my scene where the loading won't work but I cant seem to get rid of it!

    'Error removing component when merging prefab changes: Can't remove Rigidbody because HingeJoint depends on it'

    My scene doesn't have any rigidbodys?
     
  6. Jbaker08

    Jbaker08

    Joined:
    Oct 8, 2012
    Posts:
    52
    Strangely enough too, my console is printing 'Debug.Log("complete loading");'
    So i'm assuming it's completed the loading? Yet it doesnt activate. It seems very very temperamental...