Skip to content

Cannot load a scene from the OnUnloadEventCompleted  #1942

@tangx246

Description

@tangx246

Description

When trying to load a scene from OnUnloadEventCompleted, the scene does not load.

This is reported in a forum post with a workaround: https://forum.unity.com/threads/you-cannot-load-a-scene-from-the-onunloadeventcompleted-callback.1267208/

Reproduce Steps

private void SceneManager_OnUnloadEventCompleted(string sceneName, LoadSceneMode loadSceneMode, List<ulong> clientsCompleted, List<ulong> clientsTimedOut)
        {
            if (IsServer)
            {
               // this will NOT work
// NetworkManager.Singleton.SceneManager.LoadScene(m_ActiveEncounter, LoadSceneMode.Additive);
 
                // it will work if you wait a frame.
                StartCoroutine(OnUnloadEventCompleted());
            }
        }
 
private IEnumerator OnUnloadEventCompleted()
        {
            yield return 0;
            NetworkManager.Singleton.SceneManager.LoadScene(m_ActiveEncounter, LoadSceneMode.Additive);
}

Actual Outcome

The scene does not load

Expected Outcome

The scene should load without having to wait a frame for the LoadScene call

Screenshots

If applicable, add screenshots to help explain your problem.

Environment

  • OS: Windows 10
  • Unity Version: 2021.3.2
  • Netcode Version: 1.0.0-pre.8

Metadata

Metadata

Labels

type:supportQuestions or other support

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions