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
Copy file name to clipboardExpand all lines: docs/components/networkmanager.md
+50Lines changed: 50 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -256,6 +256,56 @@ public class ConnectionNotificationManager : MonoBehaviour
256
256
}
257
257
```
258
258
259
+
## NetworkManager start and stop notifications
260
+
261
+
The Netcode for GameObjects `NetworkManager` component has several events that provide additional opportunities for configuring and cleaning up depending on the notification type. The available notifications are:
262
+
263
+
-`OnInstantiated`: A static event that's invoked each time a new `NetworkManager` instance is created.
264
+
-`OnClientStarted`: An event that's invoked before returning from the `NetworkManager.StartClient` or `NetworkManager.StartHost` methods.
265
+
-`OnClientStopped`: An event that's invoked before the `NetworkManager` client or host instance is 100% shutdown.
266
+
- If you plan on joining another session from within a subscribed callback, you should use a `CoRoutine` to delay for the end of the frame or the next frame (at a minimum) to provide the `NetworkManager` time to finalize the shutdown sequence.
267
+
-`OnPreShutdown`: An event that's invoked just before the `NetworkManager` instance shuts down. This is a good place to save any states you want persisted.
268
+
-`OnServerStarted`: An event that's invoked before returning from the `NetworkManager.StartServer` or `NetworkManager.StartHost` method.
269
+
-`OnServerStopped`: An event that's invoked before the `NetworkManager` server or host instance is 100% shutdown.
270
+
- If you plan on starting another session from within a subscribed callback, you should use a `CoRoutine` to delay for the end of the frame or the next frame (at a minimum) to provide the `NetworkManager` time to finalize the shutdown sequence.
271
+
-`OnDestroying`: A static event that's invoked just before destroying `NetworkManager` instance.
272
+
273
+
### Host start and stop
274
+
275
+
When running a `NetworkManager` as a host you can receive `OnClientStarted`, `OnServerStarted`, `OnClientStopped`, and `OnServerStopped` notifications since a host is both a server and a client. Both the `OnServerStopped` and `OnClientStopped` notifications provide a `bool` as a parameter that reflects whether you were running as a host (`true` if running as a host and `false` if not) to provide you with context in the event you are using the same callback for clients too.
276
+
277
+
### Restarting a NetworkManager Session
278
+
279
+
If you plan to use a logic flow where, when an `OnClientStopped` or `OnServerStopped` event notification is triggered, you want to immediately join or start a new session, then it's highly recommended to use a `CoRoutine` within the subscribed callback that waits until the end of the frame or the next frame (at a minimum) before starting the `NetworkManager` again. This provides the `NetworkManager` time to finalize the shutdown sequence.
-[`NetworkManager` API documentation](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkManager.html)
0 commit comments