From bc9329a825d1bc34f4da3ea3c5445a904426c145 Mon Sep 17 00:00:00 2001 From: mischa <16416509+miwarnec@users.noreply.github.com> Date: Fri, 26 Jul 2024 21:19:02 +0200 Subject: [PATCH] feature: NetworkManager gentle offline scene transition after disconnect. allows studios to show a 'Connection Lost!' message for a few seconds before entering a potentially minute long black screen scene load (#3875) Co-authored-by: mischa --- Assets/Mirror/Core/NetworkManager.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Assets/Mirror/Core/NetworkManager.cs b/Assets/Mirror/Core/NetworkManager.cs index ef21e6c9f..1513b9938 100644 --- a/Assets/Mirror/Core/NetworkManager.cs +++ b/Assets/Mirror/Core/NetworkManager.cs @@ -76,6 +76,9 @@ public class NetworkManager : MonoBehaviour [Tooltip("Scene that Mirror will switch to when the server is started. Clients will recieve a Scene Message to load the server's current scene when they connect.")] public string onlineScene = ""; + [Tooltip("Optional delay that can be used after disconnecting to show a 'Connection lost...' message or similar before loading the offline scene, which may take a long time in big projects.")] + public float offlineSceneLoadDelaySeconds = 0; + // transport layer [Header("Network Info")] [Tooltip("Transport component attached to this object that server and client will use to connect")] @@ -1333,12 +1336,16 @@ void OnClientDisconnectInternal() // Check if NetworkServer.active because we can get here via Disconnect before server has started to change scenes. if (!string.IsNullOrWhiteSpace(offlineScene) && !Utils.IsSceneActive(offlineScene) && loadingSceneAsync == null && !NetworkServer.active) { - ClientChangeScene(offlineScene, SceneOperation.Normal); + Invoke(nameof(ClientChangeOfflineScene), offlineSceneLoadDelaySeconds); } networkSceneName = ""; } + // wrap ClientChangeScene call without parameters for use in Invoke. + void ClientChangeOfflineScene() => + ClientChangeScene(offlineScene, SceneOperation.Normal); + void OnClientNotReadyMessageInternal(NotReadyMessage msg) { //Debug.Log("NetworkManager.OnClientNotReadyMessageInternal");