Article directory
NetworkObject
In order to copy any Netcode-aware properties or send/receive RPCs, a GameObject must have a NetworkObject
component and at least one NetworkBehaviour
component. Any Netcode-related component, such as a NetworkBehaviour NetworkTransform
with one or more NetworkVariables
RPCs, needs to have a NetworkObject component on the same relative GameObject (or on the parent GameObject of the related GameObject).
When generating one NetworkObject
, NetworkObject.GlobalObjectIdHash
the value initially identifies the object associated with the client-instantiated network prefab resource, used to create a client-local clone. After local instantiation, each NetworkObject
is assigned a NetworkObjectId
NetworkObject that is used to associate it in the network. For example, a peer can say: "Send this RPC to the object with NetworkObjectId 103" and everyone knows which object it refers to. When NetworkObject
a unique is assigned NetworkObjectId
, it is generated on the client.
Always Replicate As Root
If set to true, the object will always be copied on the client side as the root object and its parent object will be ignored.
Synchronization Transform
Sometimes you may want to use NetworkObject
to handle transform
situations where synchronization is not required. You may have one placed in the scene NetworkObject
purely for managing game state (or similar purpose), and syncing on spawn transform
is not a cost of the initial client sync. To prevent NetworkObject
initial synchronization on build transform
, uncheck the " Synchronize Transform
" property. By default, this property is enabled (checked).
Active Scene Synchronization
When a GameObject is instantiated, it is instantiated in the currently active scene. However, sometimes you may find that you wish to change the currently active scene and want a specific NetworkObject instance to automatically migrate to the newly assigned active scene. While you could keep a list or table of NetworkObject instances and write code/logic to migrate them to newly assigned active scenes, this could be time consuming and complex depending on the size and complexity of the project. An alternative (and recommended) way to handle this issue is by enabling/checking the "Active Scene Synchronization" property of each NetworkObject that is to be automatically migrated to any new assigned scene. By default, this property is disabled/unchecked.
Scene Migration Synchronization
Similar to SceneManager.MoveGameObjectToSceneNetworkObject.ActiveSceneSynchronization
on the host or server side, this property will be automatically synchronized to client-side N instances in the scene . This is useful if you wish to migrate the instance to a specific scenario that is not the currently active scenario.etworkObject
NetworkObject
Spawn With Observers
When set to false, the NetworkObject will initially have nothing Observers
(except Server).
Dont Destroy With Owner
Whether to destroy this object if its owner is destroyed. If set to true, ownership of the object will be transferred to the server.
Auto Object Parent Sync
Whether to enable automatic NetworkObject parent object synchronization.
Afterword
Official document tutorial: