Skip to content

Commit 4722d7e

Browse files
Apply suggestions from code review
Co-authored-by: Amy Reeve <amy.reeve@unity3d.com>
1 parent 03d543a commit 4722d7e

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

com.unity.netcode.gameobjects/Documentation~/components/core/networkmanager.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -259,27 +259,28 @@ public class ConnectionNotificationManager : MonoBehaviour
259259

260260
### Instantiation and destroying
261261

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:
262+
There are two static NetworkManager events you can use to be notified when a NetworkManager is instantiated or is about to be destroyed:
263263

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.
264+
- [`NetworkManager.OnInstantiated`](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkManager.html#Unity_Netcode_NetworkManager_OnInstantiated): This is invoked when a NetworkManager is instantiated.
265+
- [`NetworkManager.OnDestroying`](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkManager.html#Unity_Netcode_NetworkManager_OnDestroying): This is invoked when a NetworkManager is about to be destroyed.
266266

267267
### When a NetworkManager is stopped
268268

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:
270269

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.
270+
Knowing when a NetworkManager has stopped is useful for establishing when it's safe to transition back to a main menu scene, or other similar tasks. There are two events you can use to be notified that the NetworkManager has finished shutting down:
272271

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.
272+
- [`NetworkManager.OnClientStopped`](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkManager.html#Unity_Netcode_NetworkManager_OnClientStopped): This is invoked on a host or client when the NetworkManager has completely shut down and is ready to be restarted.
273+
- [`NetworkManager.OnServerStopped`](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkManager.html#Unity_Netcode_NetworkManager_OnServerStopped): This is invoked on a host or server when the NetworkManager has completely shut down and is ready to be restarted.
277274

278275
Since a host is both a client and a server, the event invocation order is:
279276

280-
- OnClientStopped
281-
- OnServerStopped
282-
- _Only if the NetworkManager instance is not restarted during `OnClientStopped`_.
277+
- `OnClientStopped`
278+
- `OnServerStopped`
279+
- _Only if the NetworkManager instance is not restarted during `OnClientStopped`_.
283280

284281
> [!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.
282+
> If you restart the NetworkManager during `NetworkManager.OnClientStopped`, then it will skip the invocation of `OnServerStopped`.
283+
284+
If you need to save the state of spawned objects before they're destroyed when the NetworkManager shuts down, you can use the following event notification:
285+
286+
- [`NetworkManager.OnPreShutdown`](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkManager.html#Unity_Netcode_NetworkManager_OnPreShutdown): This is invoked prior to finalizing the NetworkManager shut down process. Any remaining spawned objects will still be instantiated and spawned when this event is invoked.

0 commit comments

Comments
 (0)