Skip to content

Commit

Permalink
fix: Do not call InternalAddPlayer twice (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpach committed Nov 28, 2019
1 parent 4c0fb9b commit 7119dd1
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions Assets/Mirror/Runtime/ClientScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,6 @@ internal static void OnSpawn(SpawnMessage msg)
}
if (LogFilter.Debug) Debug.Log($"Client spawn handler instantiating netId={msg.netId} assetID={msg.assetId} sceneId={msg.sceneId} pos={msg.position}");

// is this supposed to be the local player?
if (msg.isLocalPlayer)
{
OnSpawnMessageForLocalPlayer(msg.netId);
}

// was the object already spawned?
NetworkIdentity identity = GetExistingObject(msg.netId);

Expand Down Expand Up @@ -716,30 +710,14 @@ internal static void OnSyncEventMessage(SyncEventMessage msg)
}
}

// called for the one object in the spawn message which is the local player!
internal static void OnSpawnMessageForLocalPlayer(uint netId)
{
if (LogFilter.Debug) Debug.Log("ClientScene.OnSpawnMessageForLocalPlayer - " + readyConnection + " netId: " + netId);

// is there already an owner that is a different object??
if (readyConnection.identity != null)
{
readyConnection.identity.SetNotLocalPlayer();
}

if (NetworkIdentity.spawned.TryGetValue(netId, out NetworkIdentity localObject) && localObject != null)
{
// this object already exists
localObject.connectionToServer = readyConnection;
localObject.SetLocalPlayer();
InternalAddPlayer(localObject);
}
}

static void CheckForLocalPlayer(NetworkIdentity identity)
{
if (identity.pendingLocalPlayer)
{
if (readyConnection.identity != null && readyConnection.identity != identity)
{
readyConnection.identity.SetNotLocalPlayer();
}
// supposed to be local player, so make it the local player!

// Set isLocalPlayer to true on this NetworkIdentity and trigger OnStartLocalPlayer in all scripts on the same GO
Expand Down

0 comments on commit 7119dd1

Please sign in to comment.