Skip to content

Commit

Permalink
fix: fixing an exception and error logging when two different objects…
Browse files Browse the repository at this point in the history
… are shown and hidden on the same frame [MTT-6303] (Unity-Technologies#2535)

* fix: fixing an exception and error logging when two different objects are shown and hidden on the same frame (Unity-Technologies#2524)

* changelog entry
  • Loading branch information
jeffreyrainy authored May 2, 2023
1 parent dfd08d8 commit c0d9087
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
- Fixed issue where a client could throw an exception if abruptly disconnected from a network session with one or more spawned `NetworkObject`(s). (#2510)
- Fixed issue where invalid endpoint addresses were not being detected and returning false from NGO UnityTransport. (#2496)
- Fixed some errors that could occur if a connection is lost and the loss is detected when attempting to write to the socket. (#2495)
- Fixed an exception and error logging when two different objects are shown and hidden on the same frame (#2524)

## Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ internal bool RemoveObjectFromShowingTo(NetworkObject networkObject, ulong clien
ret = true;
}

networkObject.Observers.Remove(clientId);
if (ret)
{
networkObject.Observers.Remove(clientId);
}

return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,36 @@ public IEnumerator NetworkShowHideTest()
}
}

[UnityTest]
public IEnumerator ConcurrentShowAndHideOnDifferentObjects()
{
m_ClientId0 = m_ClientNetworkManagers[0].LocalClientId;
ShowHideObject.ClientTargetedNetworkObjects.Clear();
ShowHideObject.ClientIdToTarget = m_ClientId0;


// create 3 objects
var spawnedObject1 = SpawnObject(m_PrefabToSpawn, m_ServerNetworkManager);
var spawnedObject2 = SpawnObject(m_PrefabToSpawn, m_ServerNetworkManager);
var spawnedObject3 = SpawnObject(m_PrefabToSpawn, m_ServerNetworkManager);
m_NetSpawnedObject1 = spawnedObject1.GetComponent<NetworkObject>();
m_NetSpawnedObject2 = spawnedObject2.GetComponent<NetworkObject>();
m_NetSpawnedObject3 = spawnedObject3.GetComponent<NetworkObject>();

// get the NetworkObject on a client instance
yield return WaitForConditionOrTimeOut(RefreshNetworkObjects);
AssertOnTimeout($"Could not refresh all NetworkObjects!");

m_NetSpawnedObject1.NetworkHide(m_ClientId0);

yield return WaitForTicks(m_ServerNetworkManager, 5);

m_NetSpawnedObject1.NetworkShow(m_ClientId0);
m_NetSpawnedObject2.NetworkHide(m_ClientId0);

yield return WaitForTicks(m_ServerNetworkManager, 5);
}

[UnityTest]
public IEnumerator NetworkShowHideQuickTest()
{
Expand Down

0 comments on commit c0d9087

Please sign in to comment.