From bd7173a0350534692373295dd0d790e05024aa80 Mon Sep 17 00:00:00 2001 From: Noel Stephens Date: Wed, 11 Mar 2026 13:09:07 -0500 Subject: [PATCH 1/2] fix Fixing an issue where attachables could throw an exception if an item's attachable is attached to a node and is set to detach upon ownership change and not despawn, then if the attachable item is despawned while still attached it never detaches itself from the node during a shutdown. Fixing an issue where sorting no longer is a guaranteed order. --- .../Runtime/Components/Helpers/AttachableBehaviour.cs | 5 +++-- .../NetworkObjectNetworkClientOwnedObjectsTests.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Components/Helpers/AttachableBehaviour.cs b/com.unity.netcode.gameobjects/Runtime/Components/Helpers/AttachableBehaviour.cs index 9f97ca7bca..7038e74cd1 100644 --- a/com.unity.netcode.gameobjects/Runtime/Components/Helpers/AttachableBehaviour.cs +++ b/com.unity.netcode.gameobjects/Runtime/Components/Helpers/AttachableBehaviour.cs @@ -278,7 +278,7 @@ internal void ForceDetach() /// public override void OnNetworkPreDespawn() { - if (AutoDetach.HasFlag(AutoDetachTypes.OnDespawn)) + if (NetworkManager.ShutdownInProgress || AutoDetach.HasFlag(AutoDetachTypes.OnDespawn)) { ForceDetach(); } @@ -474,10 +474,11 @@ internal void InternalDetach() /// public void Detach() { - if (!gameObject) + if (!gameObject || NetworkObject == null || NetworkManager == null || NetworkManager.ShutdownInProgress) { return; } + if (!IsSpawned) { NetworkLog.LogError($"[{name}][Detach][Not Spawned] Cannot detach if not spawned!"); diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectNetworkClientOwnedObjectsTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectNetworkClientOwnedObjectsTests.cs index 279b4896ef..d59feae840 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectNetworkClientOwnedObjectsTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectNetworkClientOwnedObjectsTests.cs @@ -75,7 +75,7 @@ public IEnumerator WhenOwnershipIsChanged_OwnershipValuesUpdateCorrectly() Assert.IsFalse(serverBehaviour.IsOwnedByServer); Assert.AreEqual(m_ClientNetworkManagers[0].LocalClientId, serverBehaviour.OwnerClientId); - var clientObject = FindObjects.ByType(orderByIdentifier: true).Where((obj) => obj.NetworkManagerOwner == m_ClientNetworkManagers[0]).FirstOrDefault(); + var clientObject = m_ClientNetworkManagers[0].SpawnManager.SpawnedObjects.ContainsKey(serverObject.NetworkObjectId) ? m_ClientNetworkManagers[0].SpawnManager.SpawnedObjects[serverObject.NetworkObjectId] : null; Assert.IsNotNull(clientObject); Assert.IsTrue(clientObject.IsOwner); From 00ff18018fbac2b37d081472bf901f0957cdb6c1 Mon Sep 17 00:00:00 2001 From: Noel Stephens Date: Wed, 11 Mar 2026 13:29:19 -0500 Subject: [PATCH 2/2] update Adding changelog entry. --- com.unity.netcode.gameobjects/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index 75687debf2..f913a438ad 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -23,6 +23,7 @@ Additional documentation and release notes are available at [Multiplayer Documen ### Fixed +- Fixed issue where an attachable could log an error upon being de-spawned during shutdown. (#3895) ### Security