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
- Open up a scene in Unity (Scene1)
- Enter play mode and start a server
- Load in a different scene (Scene2) using the NetworkSceneManager and set that scene as active when it's loaded.
- Try to unload Scene1 using the NetworkSceneManager
- 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
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:
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
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
m_IsSceneEventActiveusing reflection when UnloadScene returns SceneEventProgressStatus.InternalNetcodeError. This could be moved toNetworkSceneManager.UnloadScene.ScenesLoadedlist insideNetworkSceneManagercontains the scene we are trying to unload by exposingScenesLoaded, we can predict if this issue will occur and just not callNetworkSceneManager.UnloadScene.Environment