Unity's NetCode multiplayer online game online battle tutorial (3)--Explanation of NetworkObject component


NetworkObject

In order to copy any Netcode-aware properties or send/receive RPCs, a GameObject must have a NetworkObjectcomponent and at least one NetworkBehaviourcomponent. Any Netcode-related component, such as a NetworkBehaviour NetworkTransformwith one or more NetworkVariablesRPCs, 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.GlobalObjectIdHashthe value initially identifies the object associated with the client-instantiated network prefab resource, used to create a client-local clone. After local instantiation, each NetworkObjectis assigned a NetworkObjectIdNetworkObject 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 NetworkObjecta 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 NetworkObjectto handle transformsituations where synchronization is not required. You may have one placed in the scene NetworkObjectpurely for managing game state (or similar purpose), and syncing on spawn transformis not a cost of the initial client sync. To prevent NetworkObjectinitial 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.etworkObjectNetworkObject

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:

Guess you like

Origin blog.csdn.net/a924282761/article/details/133189292