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. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice
Dismiss Notice
Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.

Bug You cannot load a scene from the OnUnloadEventCompleted callback.

Discussion in 'Netcode for GameObjects' started by hoesterey, Apr 13, 2022.

  1. hoesterey


    Mar 19, 2010
    From the OnUnloadEventComplete callback if you load a new scene the scene will not load. You must wait a frame before loading the new scene.

    Code (CSharp):
    1. private void SceneManager_OnUnloadEventCompleted(string sceneName, LoadSceneMode loadSceneMode, List<ulong> clientsCompleted, List<ulong> clientsTimedOut)
    2.         {
    3.             if (IsServer)
    4.             {
    5.                // this will NOT work
    6. NetworkManager.Singleton.SceneManager.LoadScene(m_ActiveEncounter, LoadSceneMode.Additive);
    8.                 // it will work if you wait a frame.
    9.                 StartCoroutine(OnUnloadEventCompleted());
    10.             }
    11.         }
    13. private IEnumerator OnUnloadEventCompleted()
    14.         {
    15.             yield return 0;
    16.             NetworkManager.Singleton.SceneManager.LoadScene(m_ActiveEncounter, LoadSceneMode.Additive);
    17. }
  2. Ishnubarak


    Aug 28, 2019
    hoesterey likes this.