- Home /
No solution, but the fact has been come to that it's not working as expected.
Why does SceneManagement.SceneManager.LoadSceneAsync stop gameplay?
Hello, I am trying to load a level asynchronously while leaving the current level playable still.
Here it states I can load a level while still playing the current one or show a progress bar. http://docs.unity3d.com/ScriptReference/Application.LoadLevelAsync.html
when I load the level asynchronously the game pauses. I'm using this just to test its "ability";
private var ao : AsyncOperation;
function Update () {
if(Input.GetMouseButtonDown(0)){
Load();
}
}
function Load(){
Debug.Log("Loading");
ao = SceneManagement.SceneManager.LoadSceneAsync(2);
while(ao.progress < 0.9){
Debug.Log("WAIT");
return ;
}
Debug.Log("DONE");
}
The current level stops, and then after the new level loads the debug messages come through.
Unity docs say:
Unity will completely load all assets and all objects in the scene in a background loading thread. 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.
It's totally wrong.
I can use
ao.allowSceneActivation = false;
but then it doesn't load the level.
Are you seeing all the log messages or, for that matter, are any of them repeating unexpectedly?
From what I can tell, it should logically only print "Loading" and "WAIT", but then return preemptively from the function. However, that wouldn't explain it pausing until the loading is completed.
If it's illogically ignoring the return statement, however, it would make more sense for it to pause until loading is completed, but then it wouldn't make sense because it's completely ignoring the return statement.
I can only see the debug messages when the new level loads, they are non repetitive.
I just have some boxes falling to see what happens, When I call the Load() function the boxes stop falling. It's behaving similar to just LoadLevel.
function Load(){
Debug.Log("Loading");
ao = Scene$$anonymous$$anagement.Scene$$anonymous$$anager.LoadSceneAsync(2);
ao.allowSceneActivation = false;
while(!ao.isDone){
Debug.Log("WAIT");
yield;
}
Debug.Log("DONE");
}
This returns repetitive debug messages correctly (Before the new scene loads). ao.allowSceneActivation = false; prevents it from actually loading.
Answer by skalev · Feb 18, 2016 at 07:04 AM
Unfortunately, this has been the case with LoadLevelAsync since Unity 3.5 (that I know).
What actually is EXTREMELY slow, is not the actual loading of the level, but the last part, that is, the activation of the scene, that causes hiccups.
You should also be aware that in editor, this behaviour is worse. In our project, we get lots of hiccups when loading parts of the level (we have it all broken up and "streaming"). However, in a build, the levels load almost without a hitch.
Unfortunately there is no real way to get around it right now that I'm aware of. The best suggestion is to have all the objects in the loaded scene disabled. This way you'll load it in and go through the activation part faster. You can then use a CoRoutine to defer the activation, and even cut it up into multiple frames, as to make it have less of a hiccup.
Thanks for the info.
I am importing a .OBJ file from a memory card which on android takes around 10sec.
I just want to load the scene only when the object has been created and leave the user on a loading screen until the .OBJ has been loaded.
I can't understand how this isn't possible when the docs say I can play a level while loading another. (This allows you to load new levels while still playing the current one, show a progress bar etc.).
Here is what I don't understand: (From the docs). isDone variable from the resulting AsyncOperation can be used to query if the level load has completed.
In my situation it will load when it's complete, which renders the isDone Boolean redundant. It just seems asynchronous level loading is identical to loading a level non-asynchronously. It's very common in games to have a loading screen. I can't accept the fact it won't work.
It loads the scene objects before it loads the user into the actual scene, so that's a plus. But it doesn't work the way the docs describe.
I think the IsDone property is used more for loading levels async additive, and not just loading it normally. I agree this is not working as the users expect. This has been long documented as something that works poorly (check the forums).
I have the same problem, when we load in the first scene from the game's main menu, my loading indicator spins for a couple of frames, and then freezes while the scene transitions and activates.
Perhaps with the addition of the scene manager some improvements will be done on this very poorly designed part of the engine.
It's definitely something that needs looking into. Cheers for the info anyways and for taking your time to reply. @$$anonymous$$o $$anonymous$$haon also.
at ODNSEV7N Test reading the text file with different line ending encodings. It made a huge performance difference with Unity 4.
Follow this Question
Related Questions
Fade in doesnt work when loading level 0 Answers
How to use Level of Detail in 2D Game ? 1 Answer
How to Add more than 2 levels? 3 Answers