Skip to content

Commit d5e2484

Browse files
doc
Updating NetworkObject documentation and in-scene placed documentation.
1 parent d8b6cde commit d5e2484

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

com.unity.netcode.gameobjects/Documentation~/basics/scenemanagement/inscene-placed-networkobjects.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,13 @@ public class MyInSceneNetworkObjectBehaviour : NetworkBehaviour
184184
> [!NOTE]
185185
> You only need to enable the NetworkObject on the server-side to be able to respawn it. Netcode for GameObjects only enables a disabled in-scene placed NetworkObject on the client-side if the server-side spawns it. This **does not** apply to dynamically spawned `NetworkObjects`. Refer to [the object pooling page](../../advanced-topics/object-pooling.md) for an example of recycling dynamically spawned NetworkObjects.
186186
187+
### Pre-disabled in-scene placed NetworkObjects
188+
189+
If you want to always have an in-scene placed NetworkObject start off as disabled and then spawn it at a later time, you only need to set its GameObject to inactive in the editor while the respective scene is open. Once you have started a networked session, you can re-enable it and then spawn it any time.
190+
187191
### Setting an in-scene placed NetworkObject to a despawned state when instantiating
188192

189-
Since in-scene placed NetworkObjects are automatically spawned when their respective scene has finished loading during a network session, you might run into the scenario where you want it to start in a despawned state until a certain condition has been met. To do this, you need to add some additional code in the `OnNetworkSpawn` part of your NetworkBehaviour component:
193+
If you want to programmatically disable an in-scene placed NetworkObject you can add some additional code in the `OnNetworkSpawn` part of a NetworkBehaviour component:
190194

191195
```csharp
192196
using UnityEngine;

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ When spawning a NetworkObject, the `NetworkObject.GlobalObjectIdHash` value init
1919

2020
You can use [NetworkBehaviours](networkbehaviour.md) to add your own custom Netcode logic to the associated NetworkObject.
2121

22+
### What is a valid NetworkObject?
23+
24+
There are basically two categories of NetworkObjects:
25+
26+
- Dynamically instantiated network prefabs.
27+
- Requirements:
28+
- It must be a valid [network prefab](./networkobject.md#network-prefabs) created within the editor.
29+
- It must be registered within a network prefab list that is assigned to your NetworkManager.
30+
- [In-scene placed](../../basics/scenemanagement/inscene-placed-networkobjects.md):
31+
- Requirements:
32+
- It can be a valid network prefab instance within a scene.
33+
- It can be a GameObject with a `NetworkObject` component created within the scene while in the editor.
34+
35+
### What is an invalid NetworkObject?
36+
37+
Any GameObjects that have `NetworkObject` components added to them during runtime is **not supported** and will result in the NetworkObject's `GlobalObjectIdHash` being zero which would eventually result in synchronization issues. In the event you make this mistake, a warning message will be logged and the NetworkObject will not get spawned.
38+
2239
### Component order
2340

2441
The order of components on a networked GameObject matters. When adding netcode components to a GameObject, ensure that the NetworkObject component is ordered before any NetworkBehaviour components.

0 commit comments

Comments
 (0)