- Home /
Loading scene with LoadSceneAsync freezes and progress jumps from 0% to 90%
I've setup some async scene loading with LoadSceneAsync method to play around with it but apparently it doesn't do anything 'asynchronous'. I copy pasted code from official Unity page so there's no mistake on my part. Here's the code
public IEnumerator LoadScene(Level _level)
{
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(GetSceneName(_level), LoadSceneMode.Single);
asyncOperation.allowSceneActivation = false;
Debug.Log("Loading progress: " + asyncOperation.progress);//should get 0 here, right?
while (!asyncOperation.isDone)
{
Debug.Log("Loading progress: " + (asyncOperation.progress * 100) + "%");
if (asyncOperation.progress >= 0.9f)
{
Debug.Log("Press the space bar to continue");
if (Input.GetKeyDown(KeyCode.Space))
asyncOperation.allowSceneActivation = true;
}
yield return null;
}
}
You would imagine to get at least few frames of update while the scene loads, so you could update progress bar or something but it's doesn't, just straight freeze from 0% to 90% (then it waits for scene activation). Anyone know how to make this while loop run with the scene load?
every time i try make a question give me an error!!!!!!
how to change the languages and voices and dialogue from start menu and connect it to all scenes?
my problem is in main menu options languages i want a script that when i choose a language from multi languages system the voices and dialogue and texts change to the language what selected from the menu i wanna a way that's don't make ma game bigger cuz i tried a way that duplicate the game size i tried to do a lot of canvases and in every canvas the language change and alot of game scenes every scene with a voice and dialogue of the chosen language that was hard take long time cuz that i wanna an easy way
Your question is too general. And it looks like you want us to write all the code for you. And this is not acceptable at Unity answer. What did you try?
https://puu.sh/CTC5N/24ca742fa5.png But after I call Scene$$anonymous$$anager.LoadSceneAsync It doesn't print out anything because it's frozen for like 3 seconds and then it snaps with all those messages at once.
Answer by Gillissie · Feb 04, 2020 at 08:36 PM
I have to agree with the original post that there is a problem here. Even if the scene is small, the progress shouldn't go like this... (from my logs): 0 (frame 1) 0 (frame 2) 0.1696721 (frame 3) 0.6801639 (frame 4) 0.9 (for 34 frames) Then finally isDone = true. If this was truly asynchronous, whatever Unity is doing during those 34 frames of 0.9 should be spread out more.
My solution is to estimate the load time (by testing), and then manually smooth it out like this:
var sceneLoader = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
float elapsed = 0.0f;
// The amount of time to spread the loading progress over.
// If the actual time is longer than this, then it will sit at maxSceneLoadProgress until it's actually finished.
// If shorter, then it will jump to maxSceneLoadProgress when finished.
// This results in a smoother scene loading progress meter than using sceneLoader.progress, which jumps quickly to 0.9 then sits on that for a while before actually finishing.
const float MAX_ELAPSE = 2.0f;
do
{
setProgressMeter(Mathf.Clamp01(elapsed / MAX_ELAPSE) * maxSceneLoadProgress);
yield return null;
elapsed += Time.deltaTime;
} while (!sceneLoader.isDone);
setProgressMeter(maxSceneLoadProgress);
Wow, this was an issue 4 years ago.. and they still haven't fixed it?
Answer by haruna9x · Mar 01, 2019 at 04:19 PM
Your scene is too small, it must be large enough to be able to see the difference. So you may have to keep the allowSceneActivation parameter to be wrong, then smooth the progress value manually. Most games use the following procedure to load scenes.
Fading the screen to black.
Load "LoadingSene" in Single mode.
Fading the screen to "LoadingScene".
Load new scenes in Single mode, delay the activation of the new scene.
Fading the screen to black.
Activate the new scene.
Fading the screen to a new scene.
I mean loading my scene takes like 5 seconds and for this time it freezes, I don't think it's a small scene ($$anonymous$$aybe it actually is). You are saying that 5 seconds freezes while loading a scene asynchronoustly are normal?
The code above is nothing wrong. I want to know how you called it. I think that 5 seconds is enough to load a world as big as Skyrim.
I have a Game$$anonymous$$anager as DontDestroyOnLoad singleton and attached SceneLoader to it. I have transition coroutine that fades screen to black, then I start coroutine that rotates progress arrow in circles and then I load a scene (Arrow doesn't move tho, cuz it's frozen). Then after scene loads I execute method attached to Scene$$anonymous$$anager.sceneLoaded to remove black screen and that's it. All I want is moving arrow in circles while the scene loads.
Your answer
Follow this Question
Related Questions
Capture reference to recently loaded scene asycn 0 Answers
AsyncOperation activating immediately even with async.allowSceneActivation = false; 0 Answers
Two async operations at the same time not working ? why ? 0 Answers
Can't access AsyncOperation instance to change allowSceneActivation 2 Answers
SceneManager.LoadScene used within promise (or async callback) does nothing 0 Answers