fix: NetworkManager - keep in DDOL if ServerOnly

- like when StopClient called for Host
This commit is contained in:
MrGadget1024 2023-02-04 21:19:08 -05:00
parent a83379fe17
commit 3d9e95e52c

View File

@ -1206,16 +1206,6 @@ void OnClientDisconnectInternal()
authenticator.OnStopClient();
}
// Get Network Manager out of DDOL before going to offline scene
// to avoid collision and let a fresh Network Manager be created.
// IMPORTANT: .gameObject can be null if StopClient is called from
// OnApplicationQuit or from tests!
if (gameObject != null
&& gameObject.scene.name == "DontDestroyOnLoad"
&& !string.IsNullOrWhiteSpace(offlineScene)
&& SceneManager.GetActiveScene().path != offlineScene)
SceneManager.MoveGameObjectToScene(gameObject, SceneManager.GetActiveScene());
// set mode BEFORE changing scene so FinishStartScene doesn't re-initialize anything.
// set mode BEFORE NetworkClient.Disconnect so StopClient only runs once.
// set mode BEFORE OnStopClient so StopClient only runs once.
@ -1235,6 +1225,16 @@ void OnClientDisconnectInternal()
// Exit here if we're now in ServerOnly mode (StopClient called in Host mode).
if (mode == NetworkManagerMode.ServerOnly) return;
// Get Network Manager out of DDOL before going to offline scene
// to avoid collision and let a fresh Network Manager be created.
// IMPORTANT: .gameObject can be null if StopClient is called from
// OnApplicationQuit or from tests!
if (gameObject != null
&& gameObject.scene.name == "DontDestroyOnLoad"
&& !string.IsNullOrWhiteSpace(offlineScene)
&& SceneManager.GetActiveScene().path != offlineScene)
SceneManager.MoveGameObjectToScene(gameObject, SceneManager.GetActiveScene());
// If StopHost called in Host mode, StopServer will change scenes after this.
// Check loadingSceneAsync to ensure we don't double-invoke the scene change.
// Check if NetworkServer.active because we can get here via Disconnect before server has started to change scenes.