Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

LoadSceneAsync / LoadLevelAsync freeze at 90% for large scenes

Discussion in 'Editor & General Support' started by GMC_Jason, Jan 15, 2016.

  1. GMC_Jason

    GMC_Jason

    Joined:
    Apr 14, 2015
    Posts:
    30
    My project has had an issue with LoadLevelAsync (now LoadSceneAsync) where it freezes (blocking the main thread) when loading large scenes. This happens in the Editor as well as builds, including on other platforms.

    I've created a test scene that you can download here:
    https://drive.google.com/file/d/0B23oFFjKUdMAV21yWFI0VDVjOWs/view?usp=sharing

    This simple scene uses LoadSceneAsync while rotating a cube in Update. If the rotating cube stops moving, it is because the game is frozen. It also detects when there has been more than 50ms between frames and calls Debug.Log. Here is some example output:

    upload_2016-1-14_16-34-19.png

    This has been an issue in our project for awhile now, even when we were using Unity 4. It seems to be an issue for others as well, but I haven't seen any solutions. Does anyone know how to get around this issue?
     
    Last edited: Jan 15, 2016
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Can you profile it with deep profiling enabled to find out what going on?
    Sounds like a bug to me. Please report the simple project you have with the bug report.
     
    GMC_Jason likes this.
  3. GMC_Jason

    GMC_Jason

    Joined:
    Apr 14, 2015
    Posts:
    30
    Sure! Looks like "Prefabs.MergePrefabs" is the culprit, as well as a few calls to "Object.FindObjectsOfType" and 16384 calls to "Destroy".

    upload_2016-1-15_12-36-25.png

    I also submitted to the bug tracker.
     
    Last edited: Jan 15, 2016
  4. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Ah so you are testing this in the editor.

    In that case it is expected and performance will depend on how many prefabs you have in your scene.

    Please use standalone player to test this kind of performance, as the editor is doing additional work which does not give you the right picture of the performance.
     
  5. GMC_Jason

    GMC_Jason

    Joined:
    Apr 14, 2015
    Posts:
    30
    Profiling the test scene on an Xbox One build doesn't lag as noticeably, and shows one "extra long" frame in the profiler:
    Screen Shot 2016-01-15 at 7.59.58 PM.png

    When loading an actual scene from my game on an Xbox One build, the profiler looks like this:
    Screen Shot 2016-01-15 at 7.52.16 PM.png

    The profiler only shows less than 1 second of stalling, but the per-frame Stopwatch says it froze for 14.353 seconds. Here's the profiler timings on that load:
    Screen Shot 2016-01-15 at 7.50.25 PM.png Screen Shot 2016-01-15 at 7.51.19 PM.png

    The difference is likely because I don't have many different prefabs/assets loading in the test scene, while my actual game's scene has about 5000 GameObjects (about 1500 unique).
     
  6. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    As a side note, can anyone tell whether "deep profiling" has any effect while profiling a target device (e.g: not the editor) ?
     
  7. Kim-Riber

    Kim-Riber

    Unity Technologies

    Joined:
    Feb 25, 2011
    Posts:
    25
    Hi. I think you are hitting a bug (that we have just fixed), where our timers wrap around at 5 seconds. Some of the numbers you have been getting seams quite low for the amount of work being done.
    Do you have a bug report case number for this?
    -Kim
     
  8. Kim-Riber

    Kim-Riber

    Unity Technologies

    Joined:
    Feb 25, 2011
    Posts:
    25
    Regarding 'deep profiling'.
    This is only supported in the editor, as it requires the assemblies to be patched and reloaded.
     
    liortal likes this.
  9. GMC_Jason

    GMC_Jason

    Joined:
    Apr 14, 2015
    Posts:
    30
    Thanks Kim! The case number is 762022.

    Does the timer wrap-around issue just affect the profiler? Or is it the cause of the stall?
     
  10. nickrapp

    nickrapp

    Administrator

    Joined:
    Oct 5, 2015
    Posts:
    54
    @GMC_Jason, if you need help getting to the bottom of that stall on Xbox One specifically, please post to the Xbox One forum and I'll take a look.
     
  11. GMC_Jason

    GMC_Jason

    Joined:
    Apr 14, 2015
    Posts:
    30
    I just used my Xbox One build as an example; it stalls on all platforms. Here's some data from the PC build:

    upload_2016-1-19_18-19-44.png

    The freeze goes down to 1804 ms if I run the build off an SSD. I can post in the Xbox One forum as well if you'd like. Also, I'm not the first user to have this issue:

    http://forum.unity3d.com/threads/scenemanagement-loadlevelasync-goes-straight-to-90.375261/
    http://forum.unity3d.com/threads/ap...the-player-and-editor-on-large-scenes.350587/
    http://forum.unity3d.com/threads/unity-completely-freeze-during-loadlevelasync.339434/
    http://forum.unity3d.com/threads/loadleveladditiveasync-hiccups.359476/
    http://answers.unity3d.com/questions/745054/loadlevelasync-application-hangs.html
    http://answers.unity3d.com/questions/503341/loadlevelasync-is-acting-like-loadlevel.html
    http://answers.unity3d.com/questions/848148/questions-about-loadlevelasync.html
    http://answers.unity3d.com/questions/979772/loadlevelasync-hiccups-on-scene-switch.html
    http://answers.unity3d.com/questions/511556/loadlevelasync-asyncoperation-isnt-helping-scene-t.html
    http://forum.unity3d.com/threads/level-streaming.276775/
     
    Last edited: Jan 20, 2016
  12. nickrapp

    nickrapp

    Administrator

    Joined:
    Oct 5, 2015
    Posts:
    54
    Ah, I had thought perhaps you were seeing an Xbox One specific bug/issue.

    Generally, there are a few things worth keeping in mind with loadlevelasync. While it will do as much as it can async, there are some things in Unity that must happen on the main thread, including calls to Awake in your game scripts. So if you have a very large scene, or expensive awake calls on your objects that can lead to loadlevelasync stalls. The other thing LoadLevelAsync does is tear down the old scene, once the new one has been loaded, which can also be the source of stalls, either because the scene being destroyed is particularly large, or because you have some expensive ondestroy calls in your scripts.

    Your callstack above in particular, is the garbage collector running. When switching scenes it's inevitable for some garbage to be generated, so it might be difficult/impossible to eliminate entirely, but there are things you can do to minimize the effects of GC. You can find some information about that here: http://docs.unity3d.com/Manual/UnderstandingAutomaticMemoryManagement.html

    Hope that helps.
     
  13. OanhDv

    OanhDv

    Joined:
    Jun 16, 2017
    Posts:
    1
    I used Unity version 5.6.0 and my LoadScenseAsyn not work at 90% @@ . Can you help me ! Thank you !