- Home /
Long freeze when loading level from asset bundle in Application.Integrate Assets in Background
I'm experimenting with asset bundles and have it now working so that I can load a level from an asset bundle with this code:
IEnumerator PreloadLevel (string levelUrl){
WWW www = WWW.LoadFromCacheOrDownload (levelUrl, versionId);
yield return www;
if (www.error != null) {
Debug.Log ("WWW error: " + www.error);
}
var ab = www.assetBundle;
}
I then load the level with Application.Loadlevel. However, Unity freezes for about 5 seconds before the level is loaded. The profiler shows that this happens in Application.Integrate Assets in Background.
Am I missing something here and is there a way I can eliminate this delay?
Try using Application.LoadLevelAsync. This should eli$$anonymous$$ate the lag.
Thanks for the suggestion, but it didn't work. Ins$$anonymous$$d of one long freeze, I get a long sequence of shorter wait times (around 100ms, also in Application.Integrate Assets in Background) ending up with the same result.
Answer by gilley033 · Mar 06, 2013 at 11:06 PM
There seems to be some discrepancy in the Unity docs regarding Asynchronous level loading. For instance, on the page for Application.LoadLevelAsync, it states:
"This allows you to load new levels while still playing the current one, show a progress bar or create a completely streaming world where you constantly load and unload different parts of the world based on the player position, without any hiccups in game play."
However, the docs then acknowledge that asynchronous loading can have an impact on game performance, or else the Application.backgroundLoadingProperty wouldn't exist.
So as far as I can tell, asynchronous loading will probably always have some impact on game performance.
The only thing you can try is changing the value for Application.backgroundLoadingPriority. Do this with the following code:
Application.backgroundLoadingPriority = ThreadPriority.Low;
More information can be found here