Class NetworkObject
A component used to identify that a GameObject in the network
Inherited Members
Namespace: Unity.Netcode
Assembly: solution.dll
Syntax
[AddComponentMenu("Netcode/Network Object", -99)]
[DisallowMultipleComponent]
public sealed class NetworkObject : MonoBehaviour
Fields
Name | Description |
---|---|
ActiveSceneSynchronization | When set to true and the active scene is changed, this will automatically migrate the NetworkObject into the new active scene on both the server and client instances. |
AlwaysReplicateAsRoot | If true, the object will always be replicated as root on clients and the parent will be ignored. |
AutoObjectParentSync | Whether or not to enable automatic NetworkObject parent synchronization. |
CheckObjectVisibility | Delegate invoked when the netcode needs to know if the object should be visible to a client, if null it will assume true |
DontDestroyWithOwner | Whether or not to destroy this object if it's owner is destroyed. If true, the objects ownership will be given to the server. |
IncludeTransformWhenSpawning | Delegate invoked when the netcode needs to know if it should include the transform when spawning the object, if null it will assume true |
OnMigratedToNewScene | Notifies when the NetworkObject is migrated into a new scene |
SceneMigrationSynchronization | When enabled (the default), if a NetworkObject is migrated to a different scene (active or not) via MoveGameObjectToScene on the server side all client instances will be synchronized and the NetworkObject migrated into the newly assigned scene. The updated scene migration will get synchronized with late joining clients as well. |
SpawnWithObservers | When set to false, the NetworkObject will be spawned with no observers initially (other than the server) |
SynchronizeTransform | Determines if the associated NetworkObject's transform will get synchronized when spawned. |
Properties
Name | Description |
---|---|
DestroyWithScene | Gets whether or not the object should be automatically removed when the scene is unloaded. |
IsLocalPlayer | Gets if the object is the personal clients player object |
IsOwnedByServer | Gets Whether or not the object is owned by anyone |
IsOwner | Gets if the object is owned by the local player or if the object is the local player object |
IsPlayerObject | Gets if this object is a player object |
IsSceneObject | Gets if the object is a SceneObject, null if it's not yet spawned but is a scene object. |
IsSpawned | Gets if the object has yet been spawned across the network |
NetworkManager | Gets the NetworkManager that owns this NetworkObject instance |
NetworkObjectId | Gets the unique Id of this object that is synced across the network |
OwnerClientId | Gets the ClientId of the owner of this NetworkObject |
PrefabIdHash | Gets the Prefab Hash Id of this object if the object is registerd as a prefab otherwise it returns 0 |
Methods
Name | Description |
---|---|
ChangeOwnership(ulong) | Changes the owner of the object. Can only be called from server |
Despawn(bool) | Despawns the GameObject of this NetworkObject and sends a destroy message for it to all connected clients. |
GetNetworkBehaviourAtOrderIndex(ushort) | |
GetObservers() | Returns Observers enumerator |
IsNetworkVisibleTo(ulong) | Whether or not this object is visible to a specific client |
NetworkHide(List<NetworkObject>, ulong) | Hides a list of NetworkObjects from the targeted client. |
NetworkHide(ulong) | Hides the NetworkObject from the targeted client. |
NetworkShow(List<NetworkObject>, ulong) | Makes a list of previously hidden NetworkObjects "netcode visible" for the client specified. |
NetworkShow(ulong) | Makes the previously hidden NetworkObject "netcode visible" to the targeted client. |
RemoveOwnership() | Removes all ownership of an object from any client. Can only be called from server |
Spawn(bool) | Spawns this NetworkObject across the network. Can only be called from the Server |
SpawnAsPlayerObject(ulong, bool) | Spawns a NetworkObject across the network and makes it the player object for the given client |
SpawnWithOwnership(ulong, bool) | Spawns a NetworkObject across the network with a given owner. Can only be called from server |
TryRemoveParent(bool) | Removes the parent of the NetworkObject's transform |
TrySetParent(NetworkObject, bool) | Set the parent of the NetworkObject transform. |
TrySetParent(GameObject, bool) | Set the parent of the NetworkObject transform. |
TrySetParent(Transform, bool) | Set the parent of the NetworkObject transform. |
WorldPositionStays() | Returns the last known cached WorldPositionStays value for this NetworkObject |