- Home /
Prevent LoadLevelAdditiveAsync from halting the app?
I'm loading in fairly big assets additively with Application.LoadLevelAdditiveAsync, and finding it troublesome that the entire application stops updating until the level has completed loading.
The level is loading in a coroutine, and I've tried adjusting the priority, but none of this seems to help.
Is there any way to load this additive level while maintaining framerate higher than 0?
Are you sure you're using it properly? It would help to see how you're using the feature to figure out why it's not working properly in your case.
I'm calling it after a UI object is clicked like this:
void SomeSortofClick() {
AsyncOperation async = Application.LoadLevelAdditiveAsync(sceneName);
StartCoroutine(LoadLevelCoroutine(async));
}
IEnumerator LoadLevelCoroutine(AsyncOperation async) {
Debug.Log("Loading: " + (async.progress*100));
yield return async;
}
Hmm.. It may be because you create the AsyncOperation in a GUI thread.
Try moving your AsyncOperation async = Application.LoadLevelAdditiveAsync(sceneName) into the coroutine.
I'm using NGUI, not the stock UI.
I had AsyncOperation async = Application.LoadLevelAdditiveAsync(sceneName) in the coroutine originally and had the same results.
Did I mention I'm working on iOS? I should have mentioned that.
I'm not sure if it's actually async on iOS. Does it do the same thing when your scene has smaller assets? Perhaps it's just becuase your assets are too big.
Answer by smoggach · Oct 20, 2014 at 08:31 PM
I don't think it can yet. There are real multi-threading plugins out there though if you really need it.
Answer by Bunny83 · Oct 20, 2014 at 08:53 PM
Well, could you try this:
IEnumerator LoadLevelCoroutine(AsyncOperation async) {
Debug.Log("Start Loading: " + (async.progress*100));
async.allowSceneActivation = false;
yield return async;
Debug.Log("Loading Done");
yield return new WaitForSeconds(2); // just for testing
Debug.Log("Activating...");
async.allowSceneActivation = true;
}
See if the actual lag happens during the loading or the activation of the scene. If it's during the activation, there's nothing you can do about that beside making your scene smaller / lighter.
PS: You do have Unity pro and iOS pro, right?
Answer by liortal · Oct 20, 2014 at 08:54 PM
Your code looks fine - you are using the Unity API as intended.
To quote from the documentation here: http://docs.unity3d.com/ScriptReference/Application.LoadLevelAdditiveAsync.html
Unity will completely load all assets and all objects in the scene in a background loading thread. This allows you to 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.
A simple test shows that although Unity loads all assets of the new scene in a background thread (I trust the documentation, i didn't see that as that thread is probably native), all of your objects' scripts will execute their Awake() methods before the async loading returns.
This code runs on the main thread, the one where all of your current scene's objects are running and updating.
So, my logic says that the more objects you have in the loaded scene, and the more complex scripts that are attached to them, the asynchronous loading CAN affect the currently executing scene.
I would perform 2 other tests:
Run the same scenario inside the editor to see what the behaviour is like.
Try to execute the same scenario, with a different scene (smaller one).
P.S: just to verify, using the LoadLevelAdditiveAsync method requires Unity PRO. Without a PRO license i believe it behaves as the regular Load.
Thanks, I've got Pro and iOS Pro. I think it may simply be that the near 100mb of content I'm loading in some cases is heavy no matter what. I was really hoping for a multithreaded solution and thought that this was it.
Your answer
Follow this Question
Related Questions
Unloading a loaded Scene when load Async for a Loading Bar 1 Answer
LoadLevel takes more time : Unity 0 Answers
Asyncchronous image loading 2 Answers
Load Level Additive Async Lag spike 0 Answers
SceneManager.LoadSceneAsync freeze loading scene in editor. 0 Answers