Skip to content

Commit d4bef43

Browse files
committed
Fix test + remove not reachable code
1 parent 74dd16e commit d4bef43

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,8 @@ internal void HandleNetworkObjectShow(bool forceSend = false)
18561856
{
18571857
if (entry.Key != null && entry.Key.IsSpawned)
18581858
{
1859+
// Try catch due to ensure that if anything throws we keep processing the list.
1860+
// This can throw if the GameObject was destroyed on this frame.
18591861
try
18601862
{
18611863
// Always push the most recent deltas when showing a NetworkObject
@@ -1885,6 +1887,8 @@ internal void HandleNetworkObjectShow(bool forceSend = false)
18851887
{
18861888
if (networkObject != null && networkObject.IsSpawned)
18871889
{
1890+
// Try catch due to ensure that if anything throws we keep processing the list.
1891+
// This can throw if the GameObject was destroyed on this frame.
18881892
try
18891893
{
18901894
if (forceSend)
@@ -2019,10 +2023,6 @@ internal void DistributeNetworkObjects(ulong clientId)
20192023
{
20202024
if (!NetworkManager.DistributedAuthorityMode)
20212025
{
2022-
if (NetworkManager.LogLevel <= LogLevel.Error)
2023-
{
2024-
NetworkLog.LogError("[DistributeNetworkObjects] called while not in Distributed Authority Mode!");
2025-
}
20262026
return;
20272027
}
20282028

@@ -2285,12 +2285,6 @@ internal void NotifyNetworkObjectsSynchronized()
22852285
/// </remarks>
22862286
internal void ShowHiddenObjectsToNewlyJoinedClient(ulong newClientId)
22872287
{
2288-
if (NetworkManager == null || NetworkManager.ShutdownInProgress && NetworkManager.LogLevel <= LogLevel.Developer)
2289-
{
2290-
NetworkLog.LogWarning($"[Internal Error] {nameof(ShowHiddenObjectsToNewlyJoinedClient)} invoked while shutdown is in progress!");
2291-
return;
2292-
}
2293-
22942288
if (!NetworkManager.DistributedAuthorityMode)
22952289
{
22962290
if (NetworkManager.LogLevel <= LogLevel.Error)
@@ -2332,12 +2326,6 @@ internal void ShowHiddenObjectsToNewlyJoinedClient(ulong newClientId)
23322326

23332327
internal void SynchronizeObjectsToNewlyJoinedClient(ulong newClientId)
23342328
{
2335-
if (NetworkManager == null || NetworkManager.ShutdownInProgress && NetworkManager.LogLevel <= LogLevel.Developer)
2336-
{
2337-
NetworkLog.LogWarning($"[Internal Error] {nameof(SynchronizeObjectsToNewlyJoinedClient)} invoked while shutdown is in progress!");
2338-
return;
2339-
}
2340-
23412329
if (!NetworkManager.DistributedAuthorityMode)
23422330
{
23432331
if (NetworkManager.LogLevel <= LogLevel.Error)

com.unity.netcode.gameobjects/Tests/Runtime/NetworkSpawnManagerTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,9 @@ public void TestClientCantAccessOtherPlayer()
100100
}
101101

102102
// client can't access other player
103-
Assert.Throws<NotServerException>(() =>
104-
{
105-
m_ClientNetworkManagers[0].SpawnManager.GetPlayerNetworkObject(otherClientSideClientId);
106-
});
103+
string expectedLog = $"[Netcode-Server Sender=0] {otherClientSideClientId} Only the server can find player objects from other clients.";
104+
LogAssert.Expect(UnityEngine.LogType.Error, expectedLog);
105+
m_ClientNetworkManagers[0].SpawnManager.GetPlayerNetworkObject(otherClientSideClientId);
107106
}
108107

109108
[Test]

0 commit comments

Comments
 (0)