Prevent AddPlayer after Additve Scene operation (#1458)

This commit is contained in:
MrGadget 2020-01-28 16:54:46 -05:00 committed by vis2k
parent b916064856
commit d52aa7e173

View File

@ -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();