diff --git a/Assets/Mirror/Core/NetworkManager.cs b/Assets/Mirror/Core/NetworkManager.cs index 13b0ef63edb..192e74a6329 100644 --- a/Assets/Mirror/Core/NetworkManager.cs +++ b/Assets/Mirror/Core/NetworkManager.cs @@ -443,7 +443,17 @@ public void StartClient() return; } - mode = NetworkManagerMode.ClientOnly; + if (mode == NetworkManagerMode.ServerOnly) + { + mode = NetworkManagerMode.Host; + + // Redirect to FinishStartHost to do all the proper setup for host mode + // Exit here after that's completed, instead of proceeding as a remote client. + FinishStartHost(); + return; + } + else + mode = NetworkManagerMode.ClientOnly; SetupClient(); @@ -1309,8 +1319,18 @@ void OnClientDisconnectInternal() // shutdown client NetworkClient.Shutdown(); - // Exit here if we're now in ServerOnly mode (StopClient called in Host mode). - if (mode == NetworkManagerMode.ServerOnly) return; + // If we're in ServerOnly mode now, StopClient was called for host client. + // We need to reset clientStarted to false so that when we return to + // Host mode, we properly respawn objects from StartClient again. + if (mode == NetworkManagerMode.ServerOnly) + { + foreach (NetworkIdentity identity in NetworkServer.spawned.Values) + identity.clientStarted = false; + + // Exit here if we're now in ServerOnly mode (StopClient called in Host mode). + // This allows the server to keep running without the host client, keeping remote clients connected. + return; + } // Get Network Manager out of DDOL before going to offline scene // to avoid collision and let a fresh Network Manager be created. diff --git a/Assets/Mirror/Core/NetworkManagerHUD.cs b/Assets/Mirror/Core/NetworkManagerHUD.cs index c3785eac8b2..a87ecd78e6e 100644 --- a/Assets/Mirror/Core/NetworkManagerHUD.cs +++ b/Assets/Mirror/Core/NetworkManagerHUD.cs @@ -150,9 +150,17 @@ void StopButtons() } else if (NetworkServer.active) { + GUILayout.BeginHorizontal(); + // stop server if server-only if (GUILayout.Button("Stop Server")) manager.StopServer(); + + // start client if server-only, engaging host mode. + if (GUILayout.Button("Start Client")) + manager.StartClient(); + + GUILayout.EndHorizontal(); } } }