diff --git a/Mirror/Runtime/ClientScene.cs b/Mirror/Runtime/ClientScene.cs index e4c2a7ddb..cbbfa58b3 100644 --- a/Mirror/Runtime/ClientScene.cs +++ b/Mirror/Runtime/ClientScene.cs @@ -273,8 +273,24 @@ public static void DestroyAllClientObjects() public static void SetLocalObject(uint netId, NetworkIdentity ni) { - // if still receiving initial state, dont set isClient - s_NetworkScene.SetLocalObject(netId, ni, s_IsSpawnFinished, false); + if (LogFilter.Debug) { Debug.Log("ClientScene.SetLocalObject " + netId + " " + ni); } + + if (ni != null) + { + // if still receiving initial state, dont set isClient + if (s_IsSpawnFinished) ni.EnableIsClient(); + + // !Contains check needed to avoid dictionary 'out of sync' error + // because SetLocalObject is called from a foreach loop + if (!NetworkIdentity.spawned.ContainsKey(netId)) + { + NetworkIdentity.spawned[netId] = ni; + } + } + else + { + NetworkIdentity.spawned[netId] = null; + } } public static GameObject FindLocalObject(uint netId) diff --git a/Mirror/Runtime/NetworkScene.cs b/Mirror/Runtime/NetworkScene.cs index 8d99aec26..62892427f 100644 --- a/Mirror/Runtime/NetworkScene.cs +++ b/Mirror/Runtime/NetworkScene.cs @@ -18,28 +18,6 @@ internal void Shutdown() ClearSpawners(); } - internal void SetLocalObject(uint netId, NetworkIdentity ni, bool isClient, bool isServer) - { - if (LogFilter.Debug) { Debug.Log("SetLocalObject " + netId + " " + ni); } - - if (ni != null) - { - if (isClient) ni.EnableIsClient(); - if (isServer) ni.EnableIsServer(); - - // !Contains check needed to avoid dictionary 'out of sync' error - // because SetLocalObject is called from a foreach loop - if (!NetworkIdentity.spawned.ContainsKey(netId)) - { - NetworkIdentity.spawned[netId] = ni; - } - } - else - { - NetworkIdentity.spawned[netId] = null; - } - } - internal static void RegisterPrefab(GameObject prefab, Guid newAssetId) { NetworkIdentity view = prefab.GetComponent(); diff --git a/Mirror/Runtime/NetworkServer.cs b/Mirror/Runtime/NetworkServer.cs index fb4e4d597..2765c2a94 100644 --- a/Mirror/Runtime/NetworkServer.cs +++ b/Mirror/Runtime/NetworkServer.cs @@ -190,7 +190,21 @@ internal static void SetLocalObjectOnServer(uint netId, NetworkIdentity ni) { if (LogFilter.Debug) { Debug.Log("SetLocalObjectOnServer " + netId + " " + ni); } - s_NetworkScene.SetLocalObject(netId, ni, false, true); + if (ni != null) + { + ni.EnableIsServer(); + + // !Contains check needed to avoid dictionary 'out of sync' error + // because SetLocalObject is called from a foreach loop + if (!NetworkIdentity.spawned.ContainsKey(netId)) + { + NetworkIdentity.spawned[netId] = ni; + } + } + else + { + NetworkIdentity.spawned[netId] = null; + } } internal static void ActivateLocalClientScene()