Skip to content

Commit ab1f25e

Browse files
fix: attachable despawn vs detach order & ownership test. (#3895)
* 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. * update Adding changelog entry.
1 parent e0e52f4 commit ab1f25e

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2323

2424
### Fixed
2525

26+
- Fixed issue where an attachable could log an error upon being de-spawned during shutdown. (#3895)
2627
- NestedNetworkVariables initialized with no value no longer throw an error. (#3891)
2728

2829
### Security

com.unity.netcode.gameobjects/Runtime/Components/Helpers/AttachableBehaviour.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ internal void ForceDetach()
278278
/// <inheritdoc/>
279279
public override void OnNetworkPreDespawn()
280280
{
281-
if (AutoDetach.HasFlag(AutoDetachTypes.OnDespawn))
281+
if (NetworkManager.ShutdownInProgress || AutoDetach.HasFlag(AutoDetachTypes.OnDespawn))
282282
{
283283
ForceDetach();
284284
}
@@ -474,10 +474,11 @@ internal void InternalDetach()
474474
/// </summary>
475475
public void Detach()
476476
{
477-
if (!gameObject)
477+
if (!gameObject || NetworkObject == null || NetworkManager == null || NetworkManager.ShutdownInProgress)
478478
{
479479
return;
480480
}
481+
481482
if (!IsSpawned)
482483
{
483484
NetworkLog.LogError($"[{name}][Detach][Not Spawned] Cannot detach if not spawned!");

com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectNetworkClientOwnedObjectsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public IEnumerator WhenOwnershipIsChanged_OwnershipValuesUpdateCorrectly()
7575
Assert.IsFalse(serverBehaviour.IsOwnedByServer);
7676
Assert.AreEqual(m_ClientNetworkManagers[0].LocalClientId, serverBehaviour.OwnerClientId);
7777

78-
var clientObject = FindObjects.ByType<NetworkObject>(orderByIdentifier: true).Where((obj) => obj.NetworkManagerOwner == m_ClientNetworkManagers[0]).FirstOrDefault();
78+
var clientObject = m_ClientNetworkManagers[0].SpawnManager.SpawnedObjects.ContainsKey(serverObject.NetworkObjectId) ? m_ClientNetworkManagers[0].SpawnManager.SpawnedObjects[serverObject.NetworkObjectId] : null;
7979

8080
Assert.IsNotNull(clientObject);
8181
Assert.IsTrue(clientObject.IsOwner);

0 commit comments

Comments
 (0)