- Home /
Smooth scene transition issue - Async Operation
Hello.
I'm having trouble to make a smooth transition between scene with a loadbar.
I'm using AsyncOperation like how it's explained in Unity's doc here, this looks pretty easy but it doesn't work well. My progress bar isn't smooth at all (I guess there are 2/3 frames where I can see update of the loading bar). Also all the debug of the AsyncOperation's progress occurs on the same frame. It looks like Unity is overloading therefore it causes little freezes. There is my code
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(scene);
asyncOperation.allowSceneActivation = false;
while (!asyncOperation.isDone)
{
print(asyncOperation.progress);
loadBar.value = asyncOperation.progress;
if (asyncOperation.progress >= 0.9f)
{
if (Input.GetKeyDown(KeyCode.Space))
asyncOperation.allowSceneActivation = true;
}
yield return null;
}
Answer by rh_galaxy · Sep 27, 2020 at 10:20 PM
You only set loadBar.value once asyncOperation.progress has reached 0.9f...
But I'm sorry to say it, there will be lagging, because it isn't fully async. Also you need to allow the scene to start after 90% which you have noticed. That will run all the Start() methods of your objects and if they take longer than a frame the game will appear to freeze. A trick I use is to set Time.timeScale = 0, and continue the loading of my level in Update() for however many loops I need, and when done I set Time.timeScale = 1. But I worked on a VR game and it was important to produce 90 fps. Still ended up fading all to black while loading, so frame freezes wouldn't be noticed.
Yeah my bad, in my (real) code loadBar value is updated correctly but still doesn't fill smooth at all.
And yeah the second problem with all Start method also happens, I will try to fix it such as you described. Thanks.