diff --git a/Assets/Mirror/Runtime/ClientScene.cs b/Assets/Mirror/Runtime/ClientScene.cs index 721d6a3df..15862be26 100644 --- a/Assets/Mirror/Runtime/ClientScene.cs +++ b/Assets/Mirror/Runtime/ClientScene.cs @@ -20,8 +20,6 @@ public static class ClientScene { static bool isSpawnFinished; - static HashSet pendingOwnerNetIds = new HashSet(); - /// /// NetworkIdentity of the localPlayer /// @@ -62,7 +60,6 @@ public static class ClientScene internal static void Shutdown() { ClearSpawners(); - pendingOwnerNetIds.Clear(); spawnableObjects = null; readyConnection = null; ready = false; @@ -502,6 +499,7 @@ internal static void OnSpawnPrefab(NetworkConnection conn, SpawnPrefabMessage ms return; } localObject.Reset(); + localObject.pendingOwner = msg.owner; ApplySpawnPayload(localObject, msg.position, msg.rotation, msg.scale, msg.payload, msg.netId); } // lookup registered factory for type: @@ -520,6 +518,7 @@ internal static void OnSpawnPrefab(NetworkConnection conn, SpawnPrefabMessage ms return; } localObject.Reset(); + localObject.pendingOwner = msg.owner; localObject.assetId = msg.assetId; ApplySpawnPayload(localObject, msg.position, msg.rotation, msg.scale, msg.payload, msg.netId); } @@ -564,6 +563,7 @@ internal static void OnSpawnSceneObject(NetworkConnection conn, SpawnSceneObject if (LogFilter.Debug) Debug.Log("Client spawn for [netId:" + msg.netId + "] [sceneId:" + msg.sceneId + "] obj:" + spawnedId.gameObject.name); spawnedId.Reset(); + spawnedId.pendingOwner = msg.owner; ApplySpawnPayload(spawnedId, msg.position, msg.rotation, msg.scale, msg.payload, msg.netId); } @@ -733,15 +733,11 @@ internal static void OnSpawnMessageForOwner(uint netId) localObject.SetLocalPlayer(); InternalAddPlayer(localObject); } - else - { - pendingOwnerNetIds.Add(netId); - } } static void CheckForOwner(NetworkIdentity identity) { - if (pendingOwnerNetIds.Contains(identity.netId)) + if (identity.pendingOwner) { // found owner, turn into a local player @@ -757,7 +753,7 @@ static void CheckForOwner(NetworkIdentity identity) } InternalAddPlayer(identity); - pendingOwnerNetIds.Remove(identity.netId); + identity.pendingOwner = false; } } } diff --git a/Assets/Mirror/Runtime/NetworkIdentity.cs b/Assets/Mirror/Runtime/NetworkIdentity.cs index 0e35b0ff1..53e9fa8a4 100644 --- a/Assets/Mirror/Runtime/NetworkIdentity.cs +++ b/Assets/Mirror/Runtime/NetworkIdentity.cs @@ -76,6 +76,8 @@ public bool isServer /// public bool isLocalPlayer { get; private set; } + internal bool pendingOwner { get; set; } + /// /// This returns true if this object is the authoritative version of the object in the distributed network application. /// This value is determined at runtime, as opposed to localPlayerAuthority which is set on the prefab. For most objects, authority is held by the server / host. For objects with localPlayerAuthority set, authority is held by the client of that player.