From d52aa7e173f0f181bea2480ad124ee13e8e979f2 Mon Sep 17 00:00:00 2001 From: MrGadget Date: Tue, 28 Jan 2020 16:54:46 -0500 Subject: [PATCH] Prevent AddPlayer after Additve Scene operation (#1458) --- Assets/Mirror/Runtime/NetworkManager.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Assets/Mirror/Runtime/NetworkManager.cs b/Assets/Mirror/Runtime/NetworkManager.cs index a06ecd317..5e5cb3094 100644 --- a/Assets/Mirror/Runtime/NetworkManager.cs +++ b/Assets/Mirror/Runtime/NetworkManager.cs @@ -810,6 +810,11 @@ public virtual void ServerChangeScene(string newSceneName) startPositions.Clear(); } + // This is only set in ClientChangeScene below...never on server. + // We need to check this in OnClientSceneChanged called from FinishLoadSceneClientOnly + // to prevent AddPlayer message after loading/unloading additive scenes + SceneOperation clientSceneOperation = SceneOperation.Normal; + internal void ClientChangeScene(string newSceneName, SceneOperation sceneOperation = SceneOperation.Normal, bool customHandling = false) { if (string.IsNullOrEmpty(newSceneName)) @@ -836,6 +841,9 @@ internal void ClientChangeScene(string newSceneName, SceneOperation sceneOperati return; } + // cache sceneOperation so we know what was done in OnClientSceneChanged called from FinishLoadSceneClientOnly + clientSceneOperation = sceneOperation; + switch (sceneOperation) { case SceneOperation.Normal: @@ -1438,7 +1446,8 @@ public virtual void OnClientSceneChanged(NetworkConnection conn) // always become ready. if (!ClientScene.ready) ClientScene.Ready(conn); - if (autoCreatePlayer && ClientScene.localPlayer == null) + // Only call AddPlayer for normal scene changes, not additive load/unload + if (clientSceneOperation == SceneOperation.Normal && autoCreatePlayer && ClientScene.localPlayer == null) { // add player if existing one is null ClientScene.AddPlayer();