Skip to content

Commit 85964c3

Browse files
fix
Fixing the issue where users might try to start NetworkManager within OnClientStopped or OnServerStopped which would result in a failed start.
1 parent 7c515b3 commit 85964c3

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,19 +1674,8 @@ internal void ShutdownInternal()
16741674
ConnectionManager.InvokeOnClientDisconnectCallback(LocalClientId);
16751675
}
16761676

1677-
if (ConnectionManager.LocalClient.IsClient)
1678-
{
1679-
// If we were a client, we want to know if we were a host
1680-
// client or not. (why we pass in "IsServer")
1681-
OnClientStopped?.Invoke(ConnectionManager.LocalClient.IsServer);
1682-
}
1683-
1684-
if (ConnectionManager.LocalClient.IsServer)
1685-
{
1686-
// If we were a server, we want to know if we were a host
1687-
// or not. (why we pass in "IsClient")
1688-
OnServerStopped?.Invoke(ConnectionManager.LocalClient.IsClient);
1689-
}
1677+
// Save off the last local client settings
1678+
var localClient = ConnectionManager.LocalClient;
16901679

16911680
// In the event shutdown is invoked within OnClientStopped or OnServerStopped, set it to false again
16921681
m_ShuttingDown = false;
@@ -1706,6 +1695,21 @@ internal void ShutdownInternal()
17061695
// can unsubscribe from tick updates and such.
17071696
NetworkTimeSystem?.Shutdown();
17081697
NetworkTickSystem = null;
1698+
1699+
1700+
if (localClient.IsClient)
1701+
{
1702+
// If we were a client, we want to know if we were a host
1703+
// client or not. (why we pass in "IsServer")
1704+
OnClientStopped?.Invoke(localClient.IsServer);
1705+
}
1706+
1707+
if (localClient.IsServer)
1708+
{
1709+
// If we were a server, we want to know if we were a host
1710+
// or not. (why we pass in "IsClient")
1711+
OnServerStopped?.Invoke(localClient.IsClient);
1712+
}
17091713
}
17101714

17111715
// Ensures that the NetworkManager is cleaned up before OnDestroy is run on NetworkObjects and NetworkBehaviours when quitting the application.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ internal unsafe void UpdateNetworkObjectSceneChanges()
12691269
foreach (var entry in NetworkObjectsToSynchronizeSceneChanges)
12701270
{
12711271
// If it fails the first update then don't add for updates
1272-
if (!entry.Value.UpdateForSceneChanges())
1272+
if (entry.Value != null && !entry.Value.UpdateForSceneChanges())
12731273
{
12741274
CleanUpDisposedObjects.Push(entry.Key);
12751275
}

0 commit comments

Comments
 (0)