You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding additional information about some events we have added but do not cover in NetworkManager.
Added additional information about starting NetworkManager within OnClientStopped or OnServerStopped.
Adding changelog entry.
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/Documentation~/components/core/networkmanager.md
+29-2Lines changed: 29 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -169,8 +169,6 @@ Subscribe to the `NetworkManager.OnClientDisconnectCallback` event to receive no
169
169
- On the client-side, the client identifier parameter is the identifier assigned to the client.
170
170
-_The exception to this is when a client is disconnected before its connection is approved._
171
171
172
-
You can also use the `NetworkManager.OnServerStopped` and `NetworkManager.OnClientStopped` callbacks to get local notifications when the server or client stops respectively.
173
-
174
172
### Connection notification manager example
175
173
176
174
Below is one example of how you can provide client connect and disconnect notifications to any type of NetworkBehaviour or MonoBehaviour derived component.
@@ -256,3 +254,32 @@ public class ConnectionNotificationManager : MonoBehaviour
256
254
}
257
255
}
258
256
```
257
+
258
+
## Additional NetworkManager notifications
259
+
260
+
### Instantiation and destroying
261
+
262
+
There are times when it could be useful to be notified when a NetworkManager has been instantiated or is about to be destroyed. There are two static NetworkManager events you can use for this:
263
+
264
+
- NetworkManager.OnInstantiated: This is invoked when a NetworkManager is instantiated.
265
+
- NetworkManager.OnDestroying: This is invoked when a NetworkManager is about to be destroyed.
266
+
267
+
### When a NetworkManager is stopped
268
+
269
+
You will almost always want to know when a NetworkManager has finished shutting down ("stopped"). This can be useful to know when it is safe to transition back to a main menu scene or you might want to perform other similar types of tasks. However, knowing when a NetworkManager has been stopped does not help if you want to save off any state that might exist on spawned objects because at that point everything will have been de-spawned and destroyed. If you run into this scenario then you can use the following event notification:
270
+
271
+
-[NetworkManager.OnPreShutdown](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.10/api/Unity.Netcode.NetworkManager.html#Unity_Netcode_NetworkManager_OnPreShutdown): This is invoked prior to finalizing the NetworkManager shutdown process. Any remaining spawned objects will still be instantiated and spawned when this event is invoked.
272
+
273
+
Similar to the started events, there are two stopped events you can subscribe to that lets you know the NetworkManager is completely shutdown ("stopped"):
274
+
275
+
-[NetworkManager.OnClientStopped](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.10/api/Unity.Netcode.NetworkManager.html#Unity_Netcode_NetworkManager_OnClientStopped): This is invoked on a Host or client when NetworkManager has completely shutdown and is ready to be restarted.
276
+
-[NetworkManager.OnServerStopped](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.10/api/Unity.Netcode.NetworkManager.html#Unity_Netcode_NetworkManager_OnServerStopped): This is invoked on a Host or Server when NetworkManager has completely shutdown and is ready to be restarted.
277
+
278
+
Since a host is both a client and a server, the event invocation order is:
279
+
280
+
- OnClientStopped
281
+
- OnServerStopped
282
+
-_Only if the NetworkManager instance is not restarted during `OnClientStopped`_.
283
+
284
+
> [!NOTE]
285
+
> If you start the NetworkManager during `NetworkManager.OnClientStopped`, then upon the NetworkManager having restarted successfully it will skip the invocation of `OnServerStopped` since it is no longer shutdown.
0 commit comments