diff --git a/Assets/Mirage/Runtime/ServerObjectManager.cs b/Assets/Mirage/Runtime/ServerObjectManager.cs index b1914fc872..13834e0cec 100644 --- a/Assets/Mirage/Runtime/ServerObjectManager.cs +++ b/Assets/Mirage/Runtime/ServerObjectManager.cs @@ -340,7 +340,10 @@ private static void ThrowIfNoCharacter(INetworkPlayer player) /// /// Assigns to the and then spawns it with /// - /// can only be set on an identity if the current value is Empty + /// can only be set to a non-zero value. + /// + /// + /// will be cleared when calling this method, this will ensure that the object is spawned using the new PrefabHash rather than SceneId /// /// /// This method is useful if you are creating network objects at runtime and both server and client know what to set on an object @@ -355,6 +358,13 @@ public void Spawn(NetworkIdentity identity, int prefabHash, INetworkPlayer owner ThrowIfPrefab(identity); identity.PrefabHash = prefabHash; + + if (identity.IsSceneObject) + { + if (logger.LogEnabled()) logger.Log($"Clearing SceneId on {identity} because setting prefabHash when spawning. Old sceneId={identity.SceneId:X} New PrefabHash:{prefabHash:X}"); + identity.ClearSceneId(); + } + Spawn(identity, owner); }