LoadLevelAsync Hiccup

I’ve scoured the forums, and found no answers to my specific questions in this fairly common topic of loading levels. So let me start off by describing the end goal. Ideally we’ll have a loading level in between scenes. This should be simple enough; however, there is a noticeable lag in between the last frame of the loading level, and the first frame of the next level, ie: the system hiccups in between the two scenes. I understand that some of this is to be expected; however, it was also my understanding that this hiccup should be minimal (~1sec max.)

I am making use of LoadLevelAsync in C#:

public IEnumerator Start() {
        AsyncOperation async = Application.LoadLevelAsync("LevelToLoad");
        yield return async;
}

And a SpriteManager2 animation for my loading icon. The animation will play until, I assume, the system has finished loading the desired level. At which point the animation stops and the screen freezes for a number of seconds prior to the new level being rendered.

My questions are as follows:

  • Does the size of the level being loaded impact the duration of the hiccup between the two levels when loading asynchronously, and if so, what restrictions can be placed on the scene to optimize load times.
  • Is there a way to minimize this gap such that a desired animation will continue to play until after the scene is ready to be displayed?

I understand that this functionality (LoadLevelAsync) is available for Unity Pro only and yes, I do have it.

1 Like

Does the incoming level have any complex initialisation code? This would run after the level loading is complete but before any game action so it could potentially account for the delay.

I am making use of a non-monobehaviour OO control system that has to initialize at the first frame; however the code is relatively simplistic. I’ll take a look into this; try disabling it and compare loading times.

On a side note, when loading the scene in unity, I also experience the same lag (switching between active editing scenes.) This causes me to question if it may be a load issue concerning the models.

I’ve run a few different tests: disabling scripts, disabling models; and it seems this issue is directly related to the complexity of the models. The scene statistics are as follows:
Draw Calls: 42
Tris: 930k Verts: 518k
Used Textures: 10 - 4.6 MB
Screen: 800x600 8xAA
VRAM usage: 31.1 MB to 44.1 MB (of 0.5GB)
VBO Total: 176 - 8.4 MB
Visible Skinned Meshes: 2

Anything not listed is 0.

At this point the only thing I can think of is to LoadLevelAdditiveAsync, and activate the second scene once everything has loaded. Although, I’m unsure as to whether I would experience the same lag when activating in the loader scene.

The lead artist is looking for something that is high res and smoothed. If the models are causing the lag due to their size, are there some good reference sources in getting lower-poly meshes to look like higher ones, clean and smooth? While I know that the capabilities will vary depending on hardware, are there recommendations or target sizes for model and scene poly-count when dealing with a web deployed application? A standalone? An iOS?

I appreciate any suggestions and will continue to dig around for this information.

I’m trying to tackle similar issues. I’m trying to do a smooth transition by going from menu level → empty level → game level with a nice effect over the top. Even going from menu → empty there’s a small hitch, and a big one going to game level.

Using the profiler in the editor, it seems like I have 2 major culprits causing me grief:

  1. Garbage collection. When entering empty level, I get a hitch in GarbageCollectAssetsProfile. I know that the docs say that perf is worse in editor than standalone, but I still see the hitch on deployed device. A ton of time is spent in TrackDependencies (50 ms), and in UnloadAssets (39 ms). Also in Destroy (23 ms)

  2. loading into the game level, I am spending a colossal amount of time in Texture.AwakeFromLoad (440 ms)

Any idea how to solve any of these issues?
thanks

is there any way in a standalone app to gradually unload assets over time instead of it pounding it all at once?
My major culprit for a big hitch is unloading unused assets between levels now, on iOS as an example.
big hitch.

One thing you could try is to set your objects to not destroy on load. Then you could run your own GC in the new scene. A concern on the iOS would be available memory with both scenes loaded.

just if anyone is still searching for solution: Unity - Scripting API: Application.backgroundLoadingPriority

2 Likes