Class NetworkObject
A component used to identify that a GameObject in the network
Inherited Members
Namespace: Unity.Netcode
Assembly: Unity.Netcode.Runtime.dll
Syntax
[AddComponentMenu("Netcode/Network Object", -99)]
[DisallowMultipleComponent]
public sealed class NetworkObject : MonoBehaviour
Fields
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.
Declaration
[Tooltip("When enabled (default disabled), spawned instances of this NetworkObject will automatically migrate to any newly assigned active scene.")]
public bool ActiveSceneSynchronization
Field Value
Type | Description |
---|---|
bool |
Remarks
- This only applies to dynamically spawned NetworkObjects.
- This only works when using integrated scene management (NetworkSceneManager).
If there are more than one scenes loaded and the currently active scene is unloaded, then typically the SceneManager will automatically assign a new active scene. Similar to DestroyWithScene being set to false, this prevents any NetworkObject from being destroyed with the unloaded active scene by migrating it into the automatically assigned active scene. Additionally, this is can be useful in some seamless scene streaming implementations. Note: Only having ActiveSceneSynchronization set to true will not synchronize clients when changing a NetworkObject's scene via MoveGameObjectToScene(GameObject,Scene). To synchronize clients of a NetworkObject's scene being changed via MoveGameObjectToScene(GameObject,Scene), make sure SceneMigrationSynchronization is enabled (it is by default).
AllowOwnerToParent
Client-Server specific, when enabled an owner of a NetworkObject can parent locally as opposed to requiring the owner to notify the server it would like to be parented. This behavior is always true when using a distributed authority network topology and does not require it to be set.
Declaration
[Tooltip("When enabled (default disabled), owner's can parent a NetworkObject locally without having to send an RPC to the server or host. Only pertinent when using client-server network topology configurations.")]
public bool AllowOwnerToParent
Field Value
Type | Description |
---|---|
bool |
AlwaysReplicateAsRoot
If true, the object will always be replicated as root on clients and the parent will be ignored.
Declaration
[Tooltip("If enabled (default disabled), instances of this NetworkObject will ignore any parent(s) it might have and replicate on clients as the root being its parent.")]
public bool AlwaysReplicateAsRoot
Field Value
Type | Description |
---|---|
bool |
AutoObjectParentSync
Whether or not to enable automatic NetworkObject parent synchronization.
Declaration
[Tooltip("When disabled (default enabled), NetworkObject parenting will not be automatically synchronized. This is typically used when you want to implement your own custom parenting solution.")]
public bool AutoObjectParentSync
Field Value
Type | Description |
---|---|
bool |
CheckObjectVisibility
Delegate invoked when the netcode needs to know if the object should be visible to a client, if null it will assume true
Declaration
public NetworkObject.VisibilityDelegate CheckObjectVisibility
Field Value
Type | Description |
---|---|
NetworkObject.VisibilityDelegate |
DeferredDespawnTick
Distributed Authority Mode Only When set, NetworkObjects despawned remotely will be delayed until the tick count specified is reached on all non-owner instances. It will still despawn immediately on the owner-local side.
Declaration
[HideInInspector]
public int DeferredDespawnTick
Field Value
Type | Description |
---|---|
int |
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.
Declaration
[Tooltip("When enabled (default disabled), instances of this NetworkObject will not be destroyed if the owning client disconnects.")]
public bool DontDestroyWithOwner
Field Value
Type | Description |
---|---|
bool |
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
Declaration
public NetworkObject.SpawnDelegate IncludeTransformWhenSpawning
Field Value
Type | Description |
---|---|
NetworkObject.SpawnDelegate |
OnDeferredDespawnComplete
If assigned, this callback will be invoked each frame update to determine if a NetworkObject that has had its despawn deferred should despawn. Use this callback to handle scenarios where you might have additional changes in state that could vindicate despawning earlier than the deferred despawn targeted future network tick.
Declaration
public NetworkObject.OnDeferedDespawnCompleteDelegateHandler OnDeferredDespawnComplete
Field Value
Type | Description |
---|---|
NetworkObject.OnDeferedDespawnCompleteDelegateHandler |
OnMigratedToNewScene
Notifies when the NetworkObject is migrated into a new scene
Declaration
public Action OnMigratedToNewScene
Field Value
Type | Description |
---|---|
Action |
Remarks
- ActiveSceneSynchronization or SceneMigrationSynchronization (or both) need to be enabled
- This only applies to dynamically spawned NetworkObjects.
- This only works when using integrated scene management (NetworkSceneManager).
OnOwnershipPermissionsFailure
If there is any callback assigned or subscriptions to this handler, then upon any ownership permissions failure that occurs during the invocation of ChangeOwnership(ulong) will trigger this notification containing an NetworkObject.OwnershipPermissionsFailureStatus.
Declaration
public NetworkObject.OnOwnershipPermissionsFailureDelegateHandler OnOwnershipPermissionsFailure
Field Value
Type | Description |
---|---|
NetworkObject.OnOwnershipPermissionsFailureDelegateHandler |
OnOwnershipRequestResponse
The NetworkObject.OnOwnershipRequestedDelegateHandler callback that can be used to control when ownership can be transferred to a non-authority client.
Declaration
public NetworkObject.OnOwnershipRequestResponseDelegateHandler OnOwnershipRequestResponse
Field Value
Type | Description |
---|---|
NetworkObject.OnOwnershipRequestResponseDelegateHandler |
Remarks
Requesting ownership requires the Ownership flags to have the RequestRequired flag set.
OnOwnershipRequested
The NetworkObject.OnOwnershipRequestedDelegateHandler callback that can be used to control when ownership can be transferred to a non-authority client.
Declaration
public NetworkObject.OnOwnershipRequestedDelegateHandler OnOwnershipRequested
Field Value
Type | Description |
---|---|
NetworkObject.OnOwnershipRequestedDelegateHandler |
Remarks
Requesting ownership requires the Ownership flags to have the RequestRequired flag set.
SceneMigrationSynchronization
When enabled (the default), if a NetworkObject is migrated to a different scene (active or not) via MoveGameObjectToScene(GameObject,Scene) 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.
Declaration
[Tooltip("When enabled (default enabled), dynamically spawned instances of this NetworkObject's migration to a different scene will automatically be synchonize amongst clients.")]
public bool SceneMigrationSynchronization
Field Value
Type | Description |
---|---|
bool |
Remarks
- This only applies to dynamically spawned NetworkObjects.
- This only works when using integrated scene management (NetworkSceneManager). Note: You can have both ActiveSceneSynchronization and SceneMigrationSynchronization enabled. The primary difference between the two is that SceneMigrationSynchronization only synchronizes clients when the server migrates a NetworkObject to a new scene. If the scene is unloaded and DestroyWithScene is true and ActiveSceneSynchronization is false and the scene is not the currently active scene, then the NetworkObject will be destroyed.
SpawnWithObservers
When set to false, the NetworkObject will be spawned with no observers initially (other than the server)
Declaration
[Tooltip("When disabled (default enabled), the NetworkObject will spawn with no observers. You control object visibility using NetworkShow. This applies to newly joining clients as well.")]
public bool SpawnWithObservers
Field Value
Type | Description |
---|---|
bool |
SyncOwnerTransformWhenParented
Determines if the owner will apply transform values sent by the parenting message.
Declaration
[Tooltip("When disabled (default enabled), the owner will not apply a server or host's transform properties when parenting changes. Primarily useful for client-server network topology configurations.")]
public bool SyncOwnerTransformWhenParented
Field Value
Type | Description |
---|---|
bool |
Remarks
When enabled, the resultant parenting transform changes sent by the authority will be applied on all instances.
When disabled, the resultant parenting transform changes sent by the authority will not be applied on the owner's instance.
When disabled, all non-owner instances will still be synchronized by the authority's transform values when parented.
When using a ClientServer network topology and an owner authoritative motion model, disabling this can help smooth parenting transitions.
When using a DistributedAuthority network topology this will have no impact on the owner's instance since only the authority/owner can parent.
SynchronizeTransform
Determines if the associated NetworkObject's transform will get synchronized when spawned.
Declaration
[Tooltip("If enabled (default enabled), newly joining clients will be synchronized with the transform of the associated GameObject this component is attached to. Typical use case scenario would be for managment objects or in-scene placed objects that don't move and already have their transform settings applied within the scene information.")]
public bool SynchronizeTransform
Field Value
Type | Description |
---|---|
bool |
Remarks
For things like in-scene placed NetworkObjects that have no visual components can help reduce the instance's initial synchronization bandwidth cost. This can also be useful for UI elements that have a predetermined fixed position.
Properties
CurrentParent
The current parent NetworkObject component instance to this NetworkObject component instance. When there is no parent then this will be null.
Declaration
public NetworkObject CurrentParent { get; }
Property Value
Type | Description |
---|---|
NetworkObject |
DestroyWithScene
Gets whether or not the object should be automatically removed when the scene is unloaded.
Declaration
public bool DestroyWithScene { get; set; }
Property Value
Type | Description |
---|---|
bool |
HasAuthority
This property can be used in client-server or distributed authority modes to determine if the local instance has authority. When in client-server mode, the server will always have authority over the NetworkObject and associated NetworkBehaviours. When in distributed authority mode, the owner is always the authority.
Declaration
public bool HasAuthority { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
When in client-server mode, authority should is not considered the same as ownership.
IsLocalPlayer
Gets if the object is the personal clients player object
Declaration
public bool IsLocalPlayer { get; }
Property Value
Type | Description |
---|---|
bool |
IsOwnedByServer
Gets Whether or not the object is owned by anyone
Declaration
public bool IsOwnedByServer { get; }
Property Value
Type | Description |
---|---|
bool |
IsOwner
Gets if the object is owned by the local player or if the object is the local player object
Declaration
public bool IsOwner { get; }
Property Value
Type | Description |
---|---|
bool |
IsOwnershipDistributable
When enabled, NetworkObject ownership is distributed amongst clients. To set Distributable during runtime, use SetOwnershipStatus(OwnershipStatus, bool, OwnershipLockActions)
Declaration
public bool IsOwnershipDistributable { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Scenarios of interest:
- If the NetworkObject is locked and the current owner is still connected, then it will not be redistributed upon a new client joining.
- If the NetworkObject has an ownership request in progress, then it will not be redistributed upon a new client joining.
- If the NetworkObject is locked but the owner is not longer connected, then it will be redistributed.
- If the NetworkObject has an ownership request in progress but the target client is no longer connected, then it will be redistributed.
IsOwnershipLocked
Returns true if the NetworkObject is has ownership locked. When locked, the NetworkObject cannot be redistributed nor can it be transferred by another client. To toggle the ownership loked status during runtime, use SetOwnershipLock(bool).
Declaration
public bool IsOwnershipLocked { get; }
Property Value
Type | Description |
---|---|
bool |
IsOwnershipRequestRequired
When true, the NetworkObject's ownership can be acquired through non-owner client requesting ownership. To set Transferable during runtime, use SetOwnershipStatus(OwnershipStatus, bool, OwnershipLockActions) To request ownership, use RequestOwnership().
Declaration
public bool IsOwnershipRequestRequired { get; }
Property Value
Type | Description |
---|---|
bool |
IsOwnershipTransferable
When true, the NetworkObject's ownership can be acquired by any non-owner client. To set Transferable during runtime, use SetOwnershipStatus(OwnershipStatus, bool, OwnershipLockActions).
Declaration
public bool IsOwnershipTransferable { get; }
Property Value
Type | Description |
---|---|
bool |
IsPlayerObject
Gets if this object is a player object
Declaration
public bool IsPlayerObject { get; }
Property Value
Type | Description |
---|---|
bool |
IsRequestInProgress
When true, the NetworkObject's ownership cannot be acquired because an ownership request is underway. In order for this status to be applied, the the NetworkObject must have the RequestRequired flag set and a non-owner client must have sent a request via RequestOwnership().
Declaration
public bool IsRequestInProgress { get; }
Property Value
Type | Description |
---|---|
bool |
IsSceneObject
Gets if the object is a SceneObject, null if it's not yet spawned but is a scene object.
Declaration
public bool? IsSceneObject { get; }
Property Value
Type | Description |
---|---|
bool? |
IsSpawned
Gets if the object has yet been spawned across the network
Declaration
public bool IsSpawned { get; }
Property Value
Type | Description |
---|---|
bool |
NetworkManager
Gets the NetworkManager that owns this NetworkObject instance
Declaration
public NetworkManager NetworkManager { get; }
Property Value
Type | Description |
---|---|
NetworkManager |
NetworkObjectId
Gets the unique Id of this object that is synced across the network
Declaration
public ulong NetworkObjectId { get; }
Property Value
Type | Description |
---|---|
ulong |
NetworkRigidbodies
All NetworkRigidbodyBase component instances associated with a NetworkObject component instance. NOTE: This is only available if a physics package is included. If not, then this will not be available!
Declaration
public List<NetworkRigidbodyBase> NetworkRigidbodies { get; }
Property Value
Type | Description |
---|---|
List<NetworkRigidbodyBase> |
Remarks
When parented, all child NetworkRigidbodyBase component instances under a NetworkObject component instance that do not have another NetworkObject component instance will be associated with the initial component instance. This list does not contain any parented child NetworkObject instances with one or more NetworkTransform component instance(s).
NetworkTransforms
All NetworkTransform component instances associated with a NetworkObject component instance.
Declaration
public List<NetworkTransform> NetworkTransforms { get; }
Property Value
Type | Description |
---|---|
List<NetworkTransform> |
Remarks
When parented, all child NetworkTransform component instances under a NetworkObject component instance that do not have another NetworkObject component instance will be associated with the initial component instance. This list does not contain any parented children NetworkObject instances with one or more NetworkTransform component instance(s).
OwnerClientId
Gets the ClientId of the owner of this NetworkObject
Declaration
public ulong OwnerClientId { get; }
Property Value
Type | Description |
---|---|
ulong |
PrefabIdHash
Gets the Prefab Hash Id of this object if the object is registerd as a prefab otherwise it returns 0
Declaration
[HideInInspector]
public uint PrefabIdHash { get; }
Property Value
Type | Description |
---|---|
uint |
Methods
ChangeOwnership(ulong)
Changes the owner of the object. Can only be called from server
Declaration
public void ChangeOwnership(ulong newOwnerClientId)
Parameters
Type | Name | Description |
---|---|---|
ulong | newOwnerClientId | The new owner clientId |
DeferDespawn(int, bool)
Distributed Authority Mode Only When invoked by the authority of the NetworkObject, this will locally despawn the NetworkObject while sending a delayed despawn to all non-authority instances. The tick offset + the authority's current known network tick (ServerTime.Tick) is when non-authority instances will despawn this NetworkObject instance.
Declaration
public void DeferDespawn(int tickOffset, bool destroy = true)
Parameters
Type | Name | Description |
---|---|---|
int | tickOffset | The number of ticks from the authority's currently known NetworkManager.ServerTime.Tick to delay the despawn. |
bool | destroy | Defaults to true, determines whether the NetworkObject will be destroyed. |
Despawn(bool)
Despawns the GameObject of this NetworkObject and sends a destroy message for it to all connected clients.
Declaration
public void Despawn(bool destroy = true)
Parameters
Type | Name | Description |
---|---|---|
bool | destroy | (true) the GameObject will be destroyed (false) the GameObject will persist after being despawned |
GetNetworkBehaviourOrderIndex(NetworkBehaviour)
Declaration
public ushort GetNetworkBehaviourOrderIndex(NetworkBehaviour instance)
Parameters
Type | Name | Description |
---|---|---|
NetworkBehaviour | instance |
Returns
Type | Description |
---|---|
ushort |
GetObservers()
Returns Observers enumerator
Declaration
public HashSet<ulong>.Enumerator GetObservers()
Returns
Type | Description |
---|---|
HashSet<ulong>.Enumerator | Observers enumerator |
HasOwnershipStatus(OwnershipStatus)
Use this method to determine if a NetworkObject has one or more ownership flags set.
Declaration
public bool HasOwnershipStatus(NetworkObject.OwnershipStatus status)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject.OwnershipStatus | status | one or more NetworkObject.OwnershipStatus flags |
Returns
Type | Description |
---|---|
bool | true if the flag(s) are set and false if the flag or any one of the flags are not set |
InstantiateAndSpawn(NetworkManager, ulong, bool, bool, bool, Vector3, Quaternion)
Declaration
public NetworkObject InstantiateAndSpawn(NetworkManager networkManager, ulong ownerClientId = 0, bool destroyWithScene = false, bool isPlayerObject = false, bool forceOverride = false, Vector3 position = default, Quaternion rotation = default)
Parameters
Type | Name | Description |
---|---|---|
NetworkManager | networkManager | The local instance of the NetworkManager connected to an session in progress. |
ulong | ownerClientId | The owner of the NetworkObject instance (defaults to server). |
bool | destroyWithScene | Whether the NetworkObject instance will be destroyed when the scene it is located within is unloaded (default is false). |
bool | isPlayerObject | Whether the NetworkObject instance is a player object or not (default is false). |
bool | forceOverride | Whether you want to force spawning the override when running as a host or server or if you want it to spawn the override for host mode and the source prefab for server. If there is an override, clients always spawn that as opposed to the source prefab (defaults to false). |
Vector3 | position | The starting poisiton of the NetworkObject instance. |
Quaternion | rotation | The starting rotation of the NetworkObject instance. |
Returns
Type | Description |
---|---|
NetworkObject | The newly instantiated and spawned NetworkObject prefab instance. |
InstantiateAndSpawn(GameObject, NetworkManager, ulong, bool, bool, bool, Vector3, Quaternion)
Declaration
public static NetworkObject InstantiateAndSpawn(GameObject networkPrefab, NetworkManager networkManager, ulong ownerClientId = 0, bool destroyWithScene = false, bool isPlayerObject = false, bool forceOverride = false, Vector3 position = default, Quaternion rotation = default)
Parameters
Type | Name | Description |
---|---|---|
GameObject | networkPrefab | The NetworkPrefab to instantiate and spawn. |
NetworkManager | networkManager | The local instance of the NetworkManager connected to an session in progress. |
ulong | ownerClientId | The owner of the NetworkObject instance (defaults to server). |
bool | destroyWithScene | Whether the NetworkObject instance will be destroyed when the scene it is located within is unloaded (default is false). |
bool | isPlayerObject | Whether the NetworkObject instance is a player object or not (default is false). |
bool | forceOverride | Whether you want to force spawning the override when running as a host or server or if you want it to spawn the override for host mode and the source prefab for server. If there is an override, clients always spawn that as opposed to the source prefab (defaults to false). |
Vector3 | position | The starting poisiton of the NetworkObject instance. |
Quaternion | rotation | The starting rotation of the NetworkObject instance. |
Returns
Type | Description |
---|---|
NetworkObject | The newly instantiated and spawned NetworkObject prefab instance. |
IsNetworkVisibleTo(ulong)
Whether or not this object is visible to a specific client
Declaration
public bool IsNetworkVisibleTo(ulong clientId)
Parameters
Type | Name | Description |
---|---|---|
ulong | clientId | The clientId of the client |
Returns
Type | Description |
---|---|
bool | True if the client knows about the object |
NetworkHide(List<NetworkObject>, ulong)
Hides a list of NetworkObjects from the targeted client.
Declaration
public static void NetworkHide(List<NetworkObject> networkObjects, ulong clientId)
Parameters
Type | Name | Description |
---|---|---|
List<NetworkObject> | networkObjects | The NetworkObjects that will become "netcode invisible" to the targeted client |
ulong | clientId | The targeted client |
Remarks
Usage: Use to stop sending updates to the targeted client, "netcode invisible", for the currently visible NetworkObjects.
Dynamically Spawned: NetworkObjects will be despawned and destroyed on the targeted client's side.
In-Scene Placed: NetworkObjects will only be despawned on the targeted client's side.
See Also:
NetworkHide(ulong)
NetworkShow(ulong) or NetworkShow(List<NetworkObject>, ulong)
NetworkHide(ulong)
Hides the NetworkObject from the targeted client.
Declaration
public void NetworkHide(ulong clientId)
Parameters
Type | Name | Description |
---|---|---|
ulong | clientId | The targeted client |
Remarks
Usage: Use to stop sending updates to the targeted client, "netcode invisible", for a currently visible NetworkObject.
Dynamically Spawned: NetworkObjects will be despawned and destroyed on the targeted client's side.
In-Scene Placed: NetworkObjects will only be despawned on the targeted client's side.
See Also:
NetworkHide(List<NetworkObject>, ulong)
NetworkShow(ulong) or NetworkShow(List<NetworkObject>, ulong)
NetworkShow(List<NetworkObject>, ulong)
Makes a list of previously hidden NetworkObjects "netcode visible" for the client specified.
Declaration
public static void NetworkShow(List<NetworkObject> networkObjects, ulong clientId)
Parameters
Type | Name | Description |
---|---|---|
List<NetworkObject> | networkObjects | The objects to become "netcode visible" to the targeted client |
ulong | clientId | The targeted client |
Remarks
Usage: Use to start sending updates for previously hidden NetworkObjects to the targeted client.
Dynamically Spawned: NetworkObjects will be instantiated and spawned on the targeted client's side.
In-Scene Placed: Already instantiated but despawned NetworkObjects will be spawned on the targeted client's side.
See Also:
NetworkShow(ulong)
NetworkHide(ulong) or NetworkHide(List<NetworkObject>, ulong)
NetworkShow(ulong)
Makes the previously hidden NetworkObject "netcode visible" to the targeted client.
Declaration
public void NetworkShow(ulong clientId)
Parameters
Type | Name | Description |
---|---|---|
ulong | clientId | The targeted client |
Remarks
Usage: Use to start sending updates for a previously hidden NetworkObject to the targeted client.
Dynamically Spawned: NetworkObjects will be instantiated and spawned on the targeted client side.
In-Scene Placed: The instantiated but despawned NetworkObjects will be spawned on the targeted client side.
See Also:
NetworkShow(ulong)
NetworkHide(ulong) or NetworkHide(List<NetworkObject>, ulong)
RemoveOwnership()
Removes all ownership of an object from any client. Can only be called from server
Declaration
public void RemoveOwnership()
RemoveOwnershipStatus(OwnershipStatus)
Use this method to remove one or more ownership flags from the NetworkObject. If you want to clear and then set, use SetOwnershipStatus(OwnershipStatus, bool, OwnershipLockActions).
Declaration
public bool RemoveOwnershipStatus(NetworkObject.OwnershipStatus status)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject.OwnershipStatus | status | the flag(s) to remove |
Returns
Type | Description |
---|---|
bool | true/false |
Remarks
If it returns false, then this means the flag(s) you are attempting to remove were not already set on the NetworkObject instance. If it returns true, then the flags were removed and an ownership update message was sent to all observers of the NetworkObject instance.
RequestOwnership()
Invoke this from a non-authority client to request ownership.
Declaration
public NetworkObject.OwnershipRequestStatus RequestOwnership()
Returns
Type | Description |
---|---|
NetworkObject.OwnershipRequestStatus |
Remarks
The NetworkObject.OwnershipRequestStatus results of requesting ownership: RequestSent: The request for ownership was sent (does not mean it will be granted, but the request was sent). AlreadyOwner: The current client is already the owner (no need to request ownership). RequestRequiredNotSet: The RequestRequired flag is not set on this NetworkObject Locked: The current owner has locked ownership which means requests are not available at this time. RequestInProgress: There is already a known request in progress. You can scan for ownership changes and try upon a change in ownership or just try again after a specific period of time or no longer attempt to request ownership.
SetOwnershipLock(bool)
Distributed Authority Only Locks ownership of a NetworkObject by the current owner.
Declaration
public bool SetOwnershipLock(bool lockOwnership = true)
Parameters
Type | Name | Description |
---|---|---|
bool | lockOwnership | defaults to lock (true) or unlock (false) |
Returns
Type | Description |
---|---|
bool | true or false depending upon lock operation's success |
SetOwnershipStatus(OwnershipStatus, bool, OwnershipLockActions)
Adds an NetworkObject.OwnershipStatus flag to the Ownership flags
Declaration
public bool SetOwnershipStatus(NetworkObject.OwnershipStatus status, bool clearAndSet = false, NetworkObject.OwnershipLockActions lockAction = OwnershipLockActions.None)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject.OwnershipStatus | status | flag(s) to update |
bool | clearAndSet | defaults to false, but when true will clear the permissions and then set the permissions flags |
NetworkObject.OwnershipLockActions | lockAction | defaults to None, but when set it to anther action type it will either lock or unlock ownership after setting the flags |
Returns
Type | Description |
---|---|
bool | true (applied)/false (not applied) |
Remarks
If it returns false, then this means the flag(s) you are attempting to set were already set on the NetworkObject instance. If it returns true, then the flags were set and an ownership update message was sent to all observers of the NetworkObject instance.
SetSceneObjectStatus(bool)
Declaration
public void SetSceneObjectStatus(bool isSceneObject = false)
Parameters
Type | Name | Description |
---|---|---|
bool | isSceneObject |
Spawn(bool)
Spawns this NetworkObject across the network. Can only be called from the Server
Declaration
public void Spawn(bool destroyWithScene = false)
Parameters
Type | Name | Description |
---|---|---|
bool | destroyWithScene | Should the object be destroyed when the scene is changed |
SpawnAsPlayerObject(ulong, bool)
Spawns a NetworkObject across the network and makes it the player object for the given client
Declaration
public void SpawnAsPlayerObject(ulong clientId, bool destroyWithScene = false)
Parameters
Type | Name | Description |
---|---|---|
ulong | clientId | The clientId who's player object this is |
bool | destroyWithScene | Should the object be destroyed when the scene is changed |
SpawnWithOwnership(ulong, bool)
Spawns a NetworkObject across the network with a given owner. Can only be called from server
Declaration
public void SpawnWithOwnership(ulong clientId, bool destroyWithScene = false)
Parameters
Type | Name | Description |
---|---|---|
ulong | clientId | The clientId to own the object |
bool | destroyWithScene | Should the object be destroyed when the scene is changed |
TryRemoveParent(bool)
Removes the parent of the NetworkObject's transform
Declaration
public bool TryRemoveParent(bool worldPositionStays = true)
Parameters
Type | Name | Description |
---|---|---|
bool | worldPositionStays | If true, the parent-relative position, scale and rotation are modified such that the object keeps the same world space position, rotation and scale as before. |
Returns
Type | Description |
---|---|
bool |
Remarks
This is a more convenient way to remove the parent without having to cast the null value to either GameObject or NetworkObject
TrySetParent(NetworkObject, bool)
Set the parent of the NetworkObject transform.
Declaration
public bool TrySetParent(NetworkObject parent, bool worldPositionStays = true)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject | parent | The new parent for this NetworkObject transform will be the child of. |
bool | worldPositionStays | If true, the parent-relative position, scale and rotation are modified such that the object keeps the same world space position, rotation and scale as before. |
Returns
Type | Description |
---|---|
bool | Whether or not reparenting was successful. |
TrySetParent(GameObject, bool)
Set the parent of the NetworkObject transform.
Declaration
public bool TrySetParent(GameObject parent, bool worldPositionStays = true)
Parameters
Type | Name | Description |
---|---|---|
GameObject | parent | The new parent for this NetworkObject transform will be the child of. |
bool | worldPositionStays | If true, the parent-relative position, scale and rotation are modified such that the object keeps the same world space position, rotation and scale as before. |
Returns
Type | Description |
---|---|
bool | Whether or not reparenting was successful. |
TrySetParent(Transform, bool)
Set the parent of the NetworkObject transform.
Declaration
public bool TrySetParent(Transform parent, bool worldPositionStays = true)
Parameters
Type | Name | Description |
---|---|---|
Transform | parent | The new parent for this NetworkObject transform will be the child of. |
bool | worldPositionStays | If true, the parent-relative position, scale and rotation are modified such that the object keeps the same world space position, rotation and scale as before. |
Returns
Type | Description |
---|---|
bool | Whether or not reparenting was successful. |
WorldPositionStays()
Returns the last known cached WorldPositionStays value for this NetworkObject
Declaration
public bool WorldPositionStays()
Returns
Type | Description |
---|---|
bool | true or false |
Remarks
When parenting NetworkObjects, the optional WorldPositionStays value is cached and synchronized with clients. This method provides access to the instance relative cached value. TrySetParent(GameObject, bool) TrySetParent(NetworkObject, bool) TrySetParent(Transform, bool)