Reputation: 3504
I am loading my game scene by calling SceneManager.LoadScene
. However, I am occasionally getting long load times when loading a game scene in my builds. I have not been able to reproduce this consistently, but while debugging this issue, I noticed that I can reproduce this problem every time in the Unity Editor (2017.3) on the first play.
If I enter play mode for the first time after the Unity Editor is launched and then click an in-game button to load my game scene, the profiler shows that Application.WaitForAsyncOperationToComplete
is taking ~9000 ms. I am having trouble debugging it because the time is spent in "Self ms".
If I re-enter play mode and repeat the same steps, subsequent runs show that WaitForAsyncOperationToComplete
only takes ~200 ms. The time jumps back up to 9000 ms if I re-open the Unity Editor and repeat the same steps.
How can I debug and fix this long "Self ms" time in WaitForAsyncOperationToComplete
? I am also wondering what could be causing this long delay only on the first play after opening the Unity Editor (and what persists in the Unity editor between play mode runs).
My profiler hierarchy looks like this:
EarlyUpdate.UpdatePreloading
- Loading.UpdatePreloading
-- UpdatePreloading
--- Application.WaitForAsyncOperationToComplete [*takes about 9000 ms, 8500 self ms*]
---- PreloadSingleStep [*takes about 500 ms*]
----- Application.LoadLevelAsync Integrate
----- Loading.AwakeFromLoad
----- (...)
See below for a screenshot of the profiler on the first play after Unity Editor is launched (note that Deep Profile is off, but the result is similar with Deep Profile on):
See below for a screenshot of profiler on subsequent playthroughs (and note that "Self ms" is down to a more reasonable ~200 ms rather than ~9000 ms):
Upvotes: 1
Views: 2444
Reputation: 41
I've seen this error before on an older version of Unity (2017). I have not seen it since I upgraded
Upvotes: 2
Reputation: 3504
Debugging approach
As a first step, I debugged the problem by systematically deleting GameObjects in the scene that was being loaded to identify which GameObject was causing the issue.
Doing this, I found that the long loading times disappeared when I deleted a particular GameObject from the scene.
(I did not investigate how to debug a long Application.WaitForAsyncOperationToComplete
"Self ms" time directly given that I was able to solve my issue with my previous approach.)
Upvotes: 2