Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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

Discussion in 'Editor & General Support' started by AshwinTheGammer, May 15, 2023.

  1. AshwinTheGammer

    AshwinTheGammer

    Joined:
    Sep 23, 2016
    Posts:
    68
    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
     

    Attached Files:

    • 11.png
      11.png
      File size:
      256 KB
      Views:
      28
    • 22.png
      22.png
      File size:
      177.7 KB
      Views:
      36
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,604
    You might need to show some code samples of what you're trying to do here.
     
  3. AshwinTheGammer

    AshwinTheGammer

    Joined:
    Sep 23, 2016
    Posts:
    68
    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.
     
    spiney199 likes this.
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,604
    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.
     
    AshwinTheGammer likes this.