From d638088a5e920edf8fff7dcb56309d9074696b66 Mon Sep 17 00:00:00 2001 From: James Frowen Date: Fri, 6 Dec 2024 16:45:31 +0000 Subject: [PATCH] feat!: clearing SceneId when spawning object with PrefabHash when spawning an object `SceneId` is used first if set. When spawning and explicitly setting `PrefabHash` mirage now clears the `SceneId` to ensure that the new `PrefabHash` is used BREAKING CHANGE: SceneId is now cleared when calling Spawn with PrefabHash --- Assets/Mirage/Runtime/ServerObjectManager.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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); }