Search Unity

[1.1.3] (Bug) LoadSceneAsync() blocks main thread one frame

Discussion in 'Addressables' started by optimise, Jun 19, 2019.

  1. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    441
    From my findings, seems like LoadSceneAsync() will block main thread one frame when call it and make it does not Async anymore. To reproduce it you can instantiate a parent game object and set it DontDestroyOnLoad(). Then call LoadSceneAsync() and instantiate another game object with parenting to parent game object. You will find that the game object not able to instantiate properly.
     
  2. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    829
    I'm not sure I understand what you are describing. LoadSceneAsync should do all the loading off the main thread, but the actual scene opening (done by the engine) does happen partly on the main thread.

    So it sounds like your actual bug is that instantiating into a DontDestroyOnLoad parent during a scene load doesn't work. Right? It might be best to file a unity bug with a repro project so I can fully understand what you are describing.
     
    optimise likes this.
  3. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    441
    You can use the project from Case 1164012. Open LoadSceneSystem.cs then comment yield return null; at line 37. After that, enter play mode and press Play button to enter Game scene. You will see LoadingPanel will fail to instantiate properly.
     
  4. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    829
    so it turns out this is a "feature" of the engine's scene loading API... https://docs.unity3d.com/ScriptReference/AsyncOperation-allowSceneActivation.html
    not much we can do about that now.

    To quote that doc page:

    When allowSceneActivation is set to false then progress is stopped at 0.9. The isDone is then maintained at false. When allowSceneActivation is set to true isDone can complete. While isDone is false, the AsyncOperation queue is stalled. For example, if a LoadSceneAsync.allowSceneActivation is set to false, and another AsyncOperation (e.g. SceneManager.UnloadSceneAsync ) is initialized, the last operation will not be called before the first allowSceneActivation is set to true.​