Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Loading scene async, script still freezes until scene loads

Discussion in 'Editor & General Support' started by Manafai, Feb 18, 2021.

  1. Manafai

    Manafai

    Joined:
    Oct 5, 2017
    Posts:
    15
    My game is comprised of one main scene and a collection of minigames that are loaded/unloaded additively.
    I load my scenes asynchronously and wait for the isDone flag in a coroutine, like so:

    Code (CSharp):
    1. IEnumerator LoadAndWait()
    2.         {
    3.             MenuNavigator.SetLoadingScreenActive(true);
    4.             MenuNavigator.SetTopPanelActive(false);
    5.             AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
    6.             while(!asyncOperation.isDone) { yield return null; }
    7.             StartActivity();
    8.         }
    MenuNavigator.SetLoadScreenActive(true) is suppose to activate the loading screen object, which is just a UI panel with an animated loading image. It's then closed inside StartActivity() once the scene is done loading.

    The problem is, the entire script that is running this code appears to completely freeze until the scene finishes loading. Debug messages that come much earlier are not written in the console and the loading screen never pops up. Even trying to Debug.Log the progress inside the while loop doesn't output anything until the scene loads.
     
  2. hjohnsen

    hjohnsen

    Joined:
    Feb 4, 2018
    Posts:
    67
    LoadSceneAsync is not async when used inside the editor.
     
    SAMYTHEBIGJUICY and Joe-Censored like this.
  3. Manafai

    Manafai

    Joined:
    Oct 5, 2017
    Posts:
    15
    Wait, what? Seriously? So the only way to check if this actually works as intended is to run a build?
     
    YulunSq likes this.
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Correct

    And last I checked, it is also not async in WebGL builds either, due to platform limitations.
     
    SAMYTHEBIGJUICY likes this.