Skip to content

Reset m_IsSceneEventActive to false after InternalNetcodeError #2722

@RubenCoucke

Description

@RubenCoucke

Description

When you try to unload a scene with the NetworkSceneManager that is not loaded using the NetworkSceneManger, then the status SceneEventProgressStatus.InternalNetcodeError is returned, with an error message because of the following code:

 if (!ScenesLoaded.ContainsKey(sceneHandle))
{
    Debug.LogError($"{nameof(UnloadScene)} internal error! {sceneName} with handle {scene.handle} is not within the internal scenes loaded dictionary!");
    return SceneEventProgressStatus.InternalNetcodeError;
}

This makes it so that any subsequent scene loads or unloads will have the status SceneEventProgressStatus.SceneEventInProgress and will fail to load/unload.

Reproduce Steps

  1. Open up a scene in Unity (Scene1)
  2. Enter play mode and start a server
  3. Load in a different scene (Scene2) using the NetworkSceneManager and set that scene as active when it's loaded.
  4. Try to unload Scene1 using the NetworkSceneManager
  5. Try to load in another scene (Scene3) using the NetworkSceneManager.

Actual Outcome

I receive a status SceneEventProgressStatus.SceneEventInProgress when loading in Scene3.

Expected Outcome

I receive a status SceneEventProgressStatus.Started when loading in Scene3.

Possible solutions

  • Right now we are resetting the field m_IsSceneEventActive using reflection when UnloadScene returns SceneEventProgressStatus.InternalNetcodeError. This could be moved to NetworkSceneManager.UnloadScene.
 var isSceneEventActiveField = typeof(NetworkSceneManager).GetField("m_IsSceneEventActive", BindingFlags.Instance | BindingFlags.NonPublic);
isSceneEventActiveField?.SetValue(NetworkManager.Singleton.SceneManager, false);
  • If we could check if the ScenesLoaded list inside NetworkSceneManager contains the scene we are trying to unload by exposing ScenesLoaded, we can predict if this issue will occur and just not call NetworkSceneManager.UnloadScene .

Environment

  • OS: Windows
  • Unity Version: 2022.3
  • Netcode Version: 1.6.0

Metadata

Metadata

Labels

priority:highThis issue has high priority and we are focusing to resolve itstat:importedStatus - Issue is tracked internally at Unitytype:bugBug Report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions