Application.WaitForAsyncOperationToComplete() causes game-freeze in Editor.

I'm creating a pause menu for my game and I have two scenes: a menu scene (Scene1) and a game scene (Scene2). I load them using the command 'SceneManager.LoadScene(1);' for the menu scene and 'SceneManager.LoadScene(2);' for the game scene.

The game mission opens successfully when I transition from the menu scene to the game scene for the first time. However, if I pause the game and return to the menu scene, and then try to go back to the game scene, the game freezes. This problem also occurs in the build version of the game.

Upon deep profiling, I found that the second 'WaitForAsyncOperationToComplete()' call is making expensive calls. I have tried minimizing my 'Start()' and 'Awake()' methods, but nothing seems to work.

I've attached some screenshots


You might need to show some code samples of what you're trying to do here.

Upon further investigation, I have identified the error in my code. The issue arises when I navigate back to the Main Menu, as I mistakenly set the TimeScale to 0. I was unaware that Unity retains the TimeScale value even when transitioning between scenes. Initially, I assumed that Unity would reset the time scale whenever I returned to the Main Menu.

1 Like

To add to this, this is true of any static values. They exist independant of scenes/assets, so they persist between scene reloads. Something to keep in mind.

1 Like