LoadSceneAsync / LoadLevelAsync freeze at 90% for large scenes

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:

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:

2464640--169606--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?

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.

1 Like

Sure! Looks like “Prefabs.MergePrefabs” is the culprit, as well as a few calls to “Object.FindObjectsOfType” and 16384 calls to “Destroy”.

I also submitted to the bug tracker.

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.

Profiling the test scene on an Xbox One build doesn’t lag as noticeably, and shows one “extra long” frame in the profiler:

When loading an actual scene from my game on an Xbox One build, the profiler looks like this:
2466297--169730--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:

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).

As a side note, can anyone tell whether “deep profiling” has any effect while profiling a target device (e.g: not the editor) ?

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

Regarding ‘deep profiling’.
This is only supported in the editor, as it requires the assemblies to be patched and reloaded.

1 Like

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?

@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.

I just used my Xbox One build as an example; it stalls on all platforms. Here’s some data from the PC build:

2472046--170225--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/application-levelload-freezes-both-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/

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: Unity - Manual: Memory in Unity

Hope that helps.

I used Unity version 5.6.0 and my LoadScenseAsyn not work at 90% @@ . Can you help me ! Thank you !