docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class NetworkTransform

    A component for syncing transforms. NetworkTransform will read the underlying transform and replicate it to clients. The replicated value will be automatically be interpolated (if active) and applied to the underlying GameObject's transform.

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    NetworkBehaviour
    NetworkTransform
    AnticipatedNetworkTransform
    Inherited Members
    NetworkBehaviour.NetworkManager
    NetworkBehaviour.RpcTarget
    NetworkBehaviour.IsLocalPlayer
    NetworkBehaviour.IsOwner
    NetworkBehaviour.IsServer
    NetworkBehaviour.HasAuthority
    NetworkBehaviour.IsSessionOwner
    NetworkBehaviour.ServerIsHost
    NetworkBehaviour.IsClient
    NetworkBehaviour.IsHost
    NetworkBehaviour.IsOwnedByServer
    NetworkBehaviour.IsSpawned
    NetworkBehaviour.NetworkObject
    NetworkBehaviour.HasNetworkObject
    NetworkBehaviour.NetworkObjectId
    NetworkBehaviour.NetworkBehaviourId
    NetworkBehaviour.GetNetworkBehaviour(ushort)
    NetworkBehaviour.OwnerClientId
    NetworkBehaviour.OnDeferringDespawn(int)
    NetworkBehaviour.OnNetworkPreSpawn(ref NetworkManager)
    NetworkBehaviour.OnNetworkPostSpawn()
    NetworkBehaviour.OnNetworkSessionSynchronized()
    NetworkBehaviour.OnInSceneObjectsSpawned()
    NetworkBehaviour.GetNetworkObject(ulong)
    NetworkBehaviour.OnReanticipate(double)
    NetworkBehaviour.m_TargetIdBeingSynchronized
    MonoBehaviour.IsInvoking()
    MonoBehaviour.CancelInvoke()
    MonoBehaviour.Invoke(string, float)
    MonoBehaviour.InvokeRepeating(string, float, float)
    MonoBehaviour.CancelInvoke(string)
    MonoBehaviour.IsInvoking(string)
    MonoBehaviour.StartCoroutine(string)
    MonoBehaviour.StartCoroutine(string, object)
    MonoBehaviour.StartCoroutine(IEnumerator)
    MonoBehaviour.StartCoroutine_Auto(IEnumerator)
    MonoBehaviour.StopCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(Coroutine)
    MonoBehaviour.StopCoroutine(string)
    MonoBehaviour.StopAllCoroutines()
    MonoBehaviour.print(object)
    MonoBehaviour.destroyCancellationToken
    MonoBehaviour.useGUILayout
    MonoBehaviour.didStart
    MonoBehaviour.didAwake
    MonoBehaviour.runInEditMode
    Behaviour.enabled
    Behaviour.isActiveAndEnabled
    Component.GetComponent(Type)
    Component.GetComponent<T>()
    Component.TryGetComponent(Type, out Component)
    Component.TryGetComponent<T>(out T)
    Component.GetComponent(string)
    Component.GetComponentInChildren(Type, bool)
    Component.GetComponentInChildren(Type)
    Component.GetComponentInChildren<T>(bool)
    Component.GetComponentInChildren<T>()
    Component.GetComponentsInChildren(Type, bool)
    Component.GetComponentsInChildren(Type)
    Component.GetComponentsInChildren<T>(bool)
    Component.GetComponentsInChildren<T>(bool, List<T>)
    Component.GetComponentsInChildren<T>()
    Component.GetComponentsInChildren<T>(List<T>)
    Component.GetComponentInParent(Type, bool)
    Component.GetComponentInParent(Type)
    Component.GetComponentInParent<T>(bool)
    Component.GetComponentInParent<T>()
    Component.GetComponentsInParent(Type, bool)
    Component.GetComponentsInParent(Type)
    Component.GetComponentsInParent<T>(bool)
    Component.GetComponentsInParent<T>(bool, List<T>)
    Component.GetComponentsInParent<T>()
    Component.GetComponents(Type)
    Component.GetComponents(Type, List<Component>)
    Component.GetComponents<T>(List<T>)
    Component.GetComponents<T>()
    Component.GetComponentIndex()
    Component.CompareTag(string)
    Component.CompareTag(TagHandle)
    Component.SendMessageUpwards(string, object, SendMessageOptions)
    Component.SendMessageUpwards(string, object)
    Component.SendMessageUpwards(string)
    Component.SendMessageUpwards(string, SendMessageOptions)
    Component.SendMessage(string, object)
    Component.SendMessage(string)
    Component.SendMessage(string, object, SendMessageOptions)
    Component.SendMessage(string, SendMessageOptions)
    Component.BroadcastMessage(string, object, SendMessageOptions)
    Component.BroadcastMessage(string, object)
    Component.BroadcastMessage(string)
    Component.BroadcastMessage(string, SendMessageOptions)
    Component.transform
    Component.gameObject
    Component.tag
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(object)
    Object.InstantiateAsync<T>(T)
    Object.InstantiateAsync<T>(T, Transform)
    Object.InstantiateAsync<T>(T, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int)
    Object.InstantiateAsync<T>(T, int, Transform)
    Object.InstantiateAsync<T>(T, int, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion, CancellationToken)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, CancellationToken)
    Object.InstantiateAsync<T>(T, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, Vector3, Quaternion, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, Vector3, Quaternion, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, InstantiateParameters, CancellationToken)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Scene)
    Object.Instantiate<T>(T, InstantiateParameters)
    Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, bool)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, bool)
    Object.Destroy(Object, float)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, bool)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.FindObjectsOfType(Type, bool)
    Object.FindObjectsByType(Type, FindObjectsSortMode)
    Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, float)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    Object.FindObjectsByType<T>(FindObjectsSortMode)
    Object.FindObjectsOfType<T>(bool)
    Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
    Object.FindObjectOfType<T>()
    Object.FindObjectOfType<T>(bool)
    Object.FindFirstObjectByType<T>()
    Object.FindAnyObjectByType<T>()
    Object.FindFirstObjectByType<T>(FindObjectsInactive)
    Object.FindAnyObjectByType<T>(FindObjectsInactive)
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.FindFirstObjectByType(Type)
    Object.FindAnyObjectByType(Type)
    Object.FindObjectOfType(Type, bool)
    Object.FindFirstObjectByType(Type, FindObjectsInactive)
    Object.FindAnyObjectByType(Type, FindObjectsInactive)
    Object.ToString()
    Object.name
    Object.hideFlags
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Unity.Netcode.Components
    Assembly: Unity.Netcode.Runtime.dll
    Syntax
    [DisallowMultipleComponent]
    [AddComponentMenu("Netcode/Network Transform")]
    public class NetworkTransform : NetworkBehaviour

    Fields

    AuthorityMode

    Determines whether this NetworkTransform instance will have state updates pushed by the server or the client owner. NetworkTransform.AuthorityModes

    Declaration
    [Tooltip("Selects who has authority (sends state updates) over the transform. If server (the default), then only server-side adjustments to the transform will be synchronized with clients. If owner (or client), then only the owner-side adjustments to the transform will be synchronized with both the server and other clients.")]
    public NetworkTransform.AuthorityModes AuthorityMode
    Field Value
    Type Description
    NetworkTransform.AuthorityModes

    AutoOwnerAuthorityTickOffset

    Pertains to Owner Authority and Interpolation
    When enabled (default), 1 additional tick is added to the total number of ticks used to calculate the tick latency ("ticks ago") as a time. This calculated time value is passed into the respective BufferedLinearInterpolator<T> and used to determine if any pending state updates in the queue should be processed. The additional tick value is only applied when:

    • The NetworkTransform is using a Owner authority mode.
    • The non-authority instance is a client (i.e. not host or server).
    • The network topology being used is ClientServer.
    Declaration
    public bool AutoOwnerAuthorityTickOffset
    Field Value
    Type Description
    bool
    Remarks

    When calculating the total tick latency as time value, the TickLatency is added to the InterpolationBufferTickOffset and if this property is enabled (and the conditions above are met) an additional tick is added to the final resultant value.
    Note: The reason behind this additional tick latency value is due to the 2 RTT timespan when a client state update is sent to the host or server (1 RTT) and the host or server relays this state update to all non-authority instances (1 RTT).

    InLocalSpace

    Sets whether the transform should be treated as local (true) or world (false) space.

    Declaration
    [Tooltip("Sets whether this transform should sync in local space or in world space")]
    public bool InLocalSpace
    Field Value
    Type Description
    bool
    Remarks

    This is synchronized by authority. During runtime, this should only be changed by the authoritative side. Non-authoritative instances will be overridden by the next authoritative state update.

    Interpolate

    When enabled (default) interpolation is applied. When disabled interpolation is disabled.

    Declaration
    public bool Interpolate
    Field Value
    Type Description
    bool
    Remarks

    This is synchronized by authority and changes to interpolation during runtime forces a teleport/full update. During runtime, this should only be changed by the authoritative side. Non-authoritative instances will be overridden by the next authoritative state update.

    InterpolationBufferTickOffset

    Adjusts the over-all tick offset (i.e. how many ticks ago) and how wide of a maximum delta time will be used for the various NetworkTransform.InterpolationTypes.

    Declaration
    public static int InterpolationBufferTickOffset
    Field Value
    Type Description
    int
    Remarks

    Note: You can adjust this value during runtime. Increasing this value will set non-authority instances that much further behind the authority instance but will increase the number of state updates to be processed. Increasing this can be useful under higher latency conditions.
    The default value is 1 tick (plus the tick latency). When running on a local network, reducing this to 0 is recommended.
    TickLatency

    OnClientRequestChange

    The handler that gets invoked when server receives a change from a client. This handler would be useful for server to modify pos/rot/scale before applying client's request.

    Declaration
    public NetworkTransform.OnClientRequestChangeDelegate OnClientRequestChange
    Field Value
    Type Description
    NetworkTransform.OnClientRequestChangeDelegate

    PositionInterpolationType

    The position interpolation type to use for the NetworkTransform instance.

    Declaration
    [Tooltip("Lerping yields a traditional linear result where smooth dampening will adjust based on the rate of change. You can mix interpolation types for position, rotation, and scale.")]
    public NetworkTransform.InterpolationTypes PositionInterpolationType
    Field Value
    Type Description
    NetworkTransform.InterpolationTypes
    Remarks
    • LegacyLerpYields the original Netcode for GameObjects lerp result.
    • LerpUses the newer linear buffer queue consumption approach that maintains a consistent time to the next target.
    • SmoothDampeningUses the newer linear buffer queue consumption approach and adjusts based on the rate of change.
    Things to consider:
    • You can have mixed interpolation types between position, rotation, and scale on the same NetworkTransform instance.
    • You can change the interpolation type during runtime, but changing between NetworkTransform.InterpolationTypes can result in a slight stutter if the object is in motion.

    PositionLerpSmoothing

    Controls position interpolation smoothing.

    Declaration
    public bool PositionLerpSmoothing
    Field Value
    Type Description
    bool
    Remarks

    When enabled, the BufferedLinearInterpolator<T> will apply a final lerping pass where the "t" parameter is calculated by dividing the frame time divided by the PositionMaxInterpolationTime.

    PositionMaxInterpolationTime

    The position interoplation maximum interpolation time.

    • The higher the value the smoother, but can result in lost data points (i.e. quick changes in direct).
    • The lower the value the more accurate/precise, but can result in slight stutter (i.e. due to jitter, latency, or a high threshold value).
    • This value can be adjusted during runtime in the event you want to dynamically adjust it based on some other value (i.e. linear velocity or the like).
    Declaration
    [Tooltip("The higher the value the smoother, but can result in lost data points (i.e. quick changes in direct). The lower the value the more accurate/precise, but can result in slight stutter (i.e. due to jitter, latency, or a high threshold value).")]
    [Range(0.01, 1)]
    public float PositionMaxInterpolationTime
    Field Value
    Type Description
    float

    PositionThreshold

    The position threshold value that triggers a delta state update by the authoritative instance.

    Declaration
    public float PositionThreshold
    Field Value
    Type Description
    float
    Remarks

    Note: setting this to zero will update position every network tick whether it changed or not.

    PositionThresholdDefault

    The default position change threshold value.
    Any changes above this threshold will be replicated.

    Declaration
    public const float PositionThresholdDefault = 0.001
    Field Value
    Type Description
    float

    RotAngleThreshold

    The rotation threshold value that triggers a delta state update by the authoritative instance.

    Declaration
    [Range(1E-05, 360)]
    public float RotAngleThreshold
    Field Value
    Type Description
    float
    Remarks
    • Minimum Value0.00001
    • Maximum Value360.0

    RotAngleThresholdDefault

    The default rotation angle change threshold value.
    Any changes above this threshold will be replicated.

    Declaration
    public const float RotAngleThresholdDefault = 0.01
    Field Value
    Type Description
    float

    RotationInterpolationType

    The rotation interpolation type to use for the NetworkTransform instance.

    Declaration
    [Tooltip("Lerping yields a traditional linear result where smooth dampening will adjust based on the rate of change. You can mix interpolation types for position, rotation, and scale.")]
    public NetworkTransform.InterpolationTypes RotationInterpolationType
    Field Value
    Type Description
    NetworkTransform.InterpolationTypes
    Remarks
    • LegacyLerpYields the original Netcode for GameObjects lerp result.
    • LerpUses the newer linear buffer queue consumption approach that maintains a consistent time to the next target.
    • SmoothDampeningUses the newer linear buffer queue consumption approach and adjusts based on the rate of change.
    Things to consider:
    • You can have mixed interpolation types between position, rotation, and scale on the same NetworkTransform instance.
    • You can change the interpolation type during runtime, but changing between NetworkTransform.InterpolationTypes can result in a slight stutter if the object is in motion.

    RotationLerpSmoothing

    Controls rotation interpolation smoothing.

    Declaration
    public bool RotationLerpSmoothing
    Field Value
    Type Description
    bool
    Remarks

    When enabled, the BufferedLinearInterpolator<T> will apply a final lerping pass where the "t" parameter is calculated by dividing the frame time divided by the RotationMaxInterpolationTime.

    RotationMaxInterpolationTime

    The rotation interoplation maximum interpolation time.

    • The higher the value the smoother, but can result in lost data points (i.e. quick changes in direct).
    • The lower the value the more accurate/precise, but can result in slight stutter (i.e. due to jitter, latency, or a high threshold value).
    • This value can be adjusted during runtime in the event you want to dynamically adjust it based on some other value (i.e. angular velocity).
    Declaration
    [Tooltip("The higher the value the smoother, but can result in lost data points (i.e. quick changes in direct). The lower the value the more accurate/precise, but can result in slight stutter (i.e. due to jitter, latency, or a high threshold value).")]
    [Range(0.01, 1)]
    public float RotationMaxInterpolationTime
    Field Value
    Type Description
    float

    ScaleInterpolationType

    The scale interpolation type to use for the NetworkTransform instance.

    Declaration
    [Tooltip("Lerping yields a traditional linear result where smooth dampening will adjust based on the rate of change. You can mix interpolation types for position, rotation, and scale.")]
    public NetworkTransform.InterpolationTypes ScaleInterpolationType
    Field Value
    Type Description
    NetworkTransform.InterpolationTypes
    Remarks
    • LegacyLerpYields the original Netcode for GameObjects lerp result.
    • LerpUses the newer linear buffer queue consumption approach that maintains a consistent time to the next target.
    • SmoothDampeningUses the newer linear buffer queue consumption approach and adjusts based on the rate of change.
    Things to consider:
    • You can have mixed interpolation types between position, rotation, and scale on the same NetworkTransform instance.
    • You can change the interpolation type during runtime, but changing between NetworkTransform.InterpolationTypes can result in a slight stutter if the object is in motion.

    ScaleLerpSmoothing

    Controls scale interpolation smoothing.

    Declaration
    public bool ScaleLerpSmoothing
    Field Value
    Type Description
    bool
    Remarks

    When enabled, the BufferedLinearInterpolator<T> will apply a final lerping pass where the "t" parameter is calculated by dividing the frame time divided by the ScaleMaxInterpolationTime.

    ScaleMaxInterpolationTime

    The scale interoplation maximum interpolation time.

    • The higher the value the smoother, but can result in lost data points (i.e. quick changes in direct).
    • The lower the value the more accurate/precise, but can result in slight stutter (i.e. due to jitter, latency, or a high threshold value).
    • This value can be adjusted during runtime in the event you want to dynamically adjust it based on some other value.
    Declaration
    [Tooltip("The higher the value the smoother, but can result in lost data points (i.e. quick changes in direct). The lower the value the more accurate/precise, but can result in slight stutter (i.e. due to jitter, latency, or a high threshold value).")]
    [Range(0.01, 1)]
    public float ScaleMaxInterpolationTime
    Field Value
    Type Description
    float

    ScaleThreshold

    The scale threshold value that triggers a delta state update by the authoritative instance.

    Declaration
    public float ScaleThreshold
    Field Value
    Type Description
    float
    Remarks

    Note: setting this to zero will update position every network tick whether it changed or not.

    ScaleThresholdDefault

    The default scale change threshold value.
    Any changes above this threshold will be replicated.

    Declaration
    public const float ScaleThresholdDefault = 0.01
    Field Value
    Type Description
    float

    SlerpPosition

    When true and interpolation is enabled, this will Slerp to the target position.

    Declaration
    [Tooltip("When enabled the position interpolator will Slerp towards its current target position.")]
    public bool SlerpPosition
    Field Value
    Type Description
    bool
    Remarks

    This is synchronized by authority and only applies to position interpolation. During runtime, this should only be changed by the authoritative side. Non-authoritative instances will be overridden by the next authoritative state update.

    SwitchTransformSpaceWhenParented

    When enabled, the NetworkTransform will automatically handle transitioning into the respective transform space when its NetworkObject parent changes.
    When parented: Automatically transitions into local space and coverts any existing pending interpolated states to local space on non-authority instances.
    When deparented: Automatically transitions into world space and converts any existing pending interpolated states to world space on non-authority instances.
    Set on the root NetworkTransform instance (nested NetworkTransform components should be pre-set in-editor to local space.

    Declaration
    public bool SwitchTransformSpaceWhenParented
    Field Value
    Type Description
    bool
    Remarks

    Only works with NetworkTransform components that are not paired with a NetworkRigidbody or NetworkRigidbody2D component that is configured to use the rigid body for motion.
    TickSyncChildren will automatically be set when this is enabled. Does not auto-synchronize clients if changed on the authority instance during runtime (i.e. apply this setting in-editor).

    SyncPositionX

    When enabled (default), the x component of position will be synchronized by authority.

    Declaration
    public bool SyncPositionX
    Field Value
    Type Description
    bool
    Remarks

    Changes to this on non-authoritative instances has no effect.

    SyncPositionY

    When enabled (default), the y component of position will be synchronized by authority.

    Declaration
    public bool SyncPositionY
    Field Value
    Type Description
    bool
    Remarks

    Changes to this on non-authoritative instances has no effect.

    SyncPositionZ

    When enabled (default), the z component of position will be synchronized by authority.

    Declaration
    public bool SyncPositionZ
    Field Value
    Type Description
    bool
    Remarks

    Changes to this on non-authoritative instances has no effect.

    SyncRotAngleX

    When enabled (default), the x component of rotation will be synchronized by authority.

    Declaration
    public bool SyncRotAngleX
    Field Value
    Type Description
    bool
    Remarks

    When UseQuaternionSynchronization is enabled this does not apply. Changes to this on non-authoritative instances has no effect.

    SyncRotAngleY

    When enabled (default), the y component of rotation will be synchronized by authority.

    Declaration
    public bool SyncRotAngleY
    Field Value
    Type Description
    bool
    Remarks

    When UseQuaternionSynchronization is enabled this does not apply. Changes to this on non-authoritative instances has no effect.

    SyncRotAngleZ

    When enabled (default), the z component of rotation will be synchronized by authority.

    Declaration
    public bool SyncRotAngleZ
    Field Value
    Type Description
    bool
    Remarks

    When UseQuaternionSynchronization is enabled this does not apply. Changes to this on non-authoritative instances has no effect.

    SyncScaleX

    When enabled (default), the x component of scale will be synchronized by authority.

    Declaration
    public bool SyncScaleX
    Field Value
    Type Description
    bool
    Remarks

    Changes to this on non-authoritative instances has no effect.

    SyncScaleY

    When enabled (default), the y component of scale will be synchronized by authority.

    Declaration
    public bool SyncScaleY
    Field Value
    Type Description
    bool
    Remarks

    Changes to this on non-authoritative instances has no effect.

    SyncScaleZ

    When enabled (default), the z component of scale will be synchronized by authority.

    Declaration
    public bool SyncScaleZ
    Field Value
    Type Description
    bool
    Remarks

    Changes to this on non-authoritative instances has no effect.

    TickSyncChildren

    When enabled, any parented NetworkObjects (children) of this NetworkObject will be forced to synchronize their transform when this NetworkObject instance sends a state update.
    This can help to reduce out of sync updates that can lead to slight jitter between a parent and its child/children.

    Declaration
    [Tooltip("When enabled, any parented children of this instance will send a state update when this instance sends a state update. If this instance doesn't send a state update, the children will still send state updates when reaching their axis specified threshold delta. Children do not have to have this setting enabled.")]
    public bool TickSyncChildren
    Field Value
    Type Description
    bool
    Remarks
    • If this is set on a child and the parent does not have this set then the child will not be tick synchronized with its parent.
    • If the parent instance does not send any state updates, the children will still send state updates when exceeding axis delta threshold.
    • This does not need to be set on children to be applied.

    UseHalfFloatPrecision

    Enable this to use half float precision for position, rotation, and scale.
    When enabled, delta position synchronization is used.

    Declaration
    [Tooltip("When enabled, this will use half float precision values for position (uses delta position updating), rotation (except when Quaternion compression is enabled), and scale.")]
    public bool UseHalfFloatPrecision
    Field Value
    Type Description
    bool
    Remarks

    This is synchronized by authority. During runtime, this should only be changed by the authoritative side. Non-authoritative instances will be overridden by the next authoritative state update.

    UseQuaternionCompression

    Enabled this on the authority side for quaternion compression

    Declaration
    [Tooltip("When enabled, this uses a smallest three implementation that reduces full Quaternion updates down to the size of an unsigned integer (ignores half float precision settings).")]
    public bool UseQuaternionCompression
    Field Value
    Type Description
    bool
    Remarks

    This has a lower precision than half float precision. Recommended only for low precision scenarios. UseHalfFloatPrecision provides better precision at roughly half the cost of a full quaternion update.
    This is synchronized by authority. During runtime, this should only be changed by the authoritative side. Non-authoritative instances will be overridden by the next authoritative state update.

    UseQuaternionSynchronization

    Enable this on the authority side for quaternion synchronization.

    Declaration
    [Tooltip("When enabled, this will synchronize the full Quaternion (i.e. all Euler rotation axis are updated if one axis has a delta)")]
    public bool UseQuaternionSynchronization
    Field Value
    Type Description
    bool
    Remarks

    This is synchronized by authority. During runtime, this should only be changed by the authoritative side. Non-authoritative instances will be overridden by the next authoritative state update.

    UseUnreliableDeltas

    Enabled by default. When set (enabled by default), NetworkTransform will send common state updates using unreliable network delivery to provide a higher tolerance to poor network conditions (especially packet loss). When disabled, all state updates are sent using a reliable fragmented sequenced network delivery.

    Declaration
    [Tooltip("When set, NetworkTransform will send common state updates using unreliable network delivery to provide a higher tolerance to poor network conditions (especially packet loss). When disabled, all state updates are sent using reliable fragmented sequenced network delivery.")]
    public bool UseUnreliableDeltas
    Field Value
    Type Description
    bool
    Remarks

    The following more critical state updates are still sent as reliable fragmented sequenced:

    • The initial synchronization state update.
    • The teleporting state update.
    • When using half float precision and the `NetworkDeltaPosition` delta exceeds the maximum delta forcing the axis in question to be collapsed into the core base position, this state update will be sent as reliable fragmented sequenced.
    In order to preserve a continual consistency of axial values when unreliable delta messaging is enabled (due to the possibility of dropping packets), NetworkTransform instances will send 1 axial frame synchronization update per second (only for the axis marked to synchronize are sent as reliable fragmented sequenced) as long as a delta state update had been previously sent. When a NetworkObject is at rest, axial frame synchronization updates are not sent.

    m_AddLogEntry

    Declaration
    protected NetworkTransform.AddLogEntryHandler m_AddLogEntry
    Field Value
    Type Description
    NetworkTransform.AddLogEntryHandler

    m_CachedNetworkManager

    Internally used by NetworkTransform to keep track of the NetworkManager instance assigned to this this NetworkBehaviour derived class instance.

    Declaration
    protected NetworkManager m_CachedNetworkManager
    Field Value
    Type Description
    NetworkManager

    Properties

    CanCommitToTransform

    Used to determine who can write to this transform. Server only for this transform. Changing this value alone in a child implementation will not allow you to create a NetworkTransform which can be written to by clients. See the ClientNetworkTransform Sample in the package samples for how to implement a NetworkTransform with client write support. If using different values, please use RPCs to write to the server. Netcode doesn't support client side network variable writing

    Declaration
    public bool CanCommitToTransform { get; protected set; }
    Property Value
    Type Description
    bool

    PositionInLocalSpace

    Returns true if position is currently in local space and false if it is in world space.

    Declaration
    protected bool PositionInLocalSpace { get; }
    Property Value
    Type Description
    bool

    RotationInLocalSpace

    Returns true if rotation is currently in local space and false if it is in world space.

    Declaration
    protected bool RotationInLocalSpace { get; }
    Property Value
    Type Description
    bool

    Methods

    ApplyAuthoritativeState()

    Applies the authoritative state to the transform

    Declaration
    protected void ApplyAuthoritativeState()

    Awake()

    Create interpolators when first instantiated to avoid memory allocations if the associated NetworkObject persists (i.e. despawned but not destroyed or pools)

    Declaration
    protected virtual void Awake()

    GetHalfPositionState()

    Declaration
    protected NetworkDeltaPosition GetHalfPositionState()
    Returns
    Type Description
    NetworkDeltaPosition

    GetScale(bool)

    Helper method that returns the scale of the transform.

    Declaration
    public Vector3 GetScale(bool getCurrentState = false)
    Parameters
    Type Name Description
    bool getCurrentState

    Authority always returns the space relative transform scale (whether true or false).
    Non-authority:
    When false (default): returns the space relative transform scale.
    When true: returns the authority scale from the most recent state update.

    Returns
    Type Description
    Vector3

    Vector3

    Remarks

    When invoked on the non-authority side:
    If getCurrentState is true then it will return the most current authority scale from the most recent state update. This can be useful if interpolation is enabled and you need to determine the final target scale.
    When invoked on the authority side:
    It will always return the space relative scale.

    GetSpaceRelativePosition(bool)

    Helper method that returns the space relative position of the transform.

    Declaration
    public Vector3 GetSpaceRelativePosition(bool getCurrentState = false)
    Parameters
    Type Name Description
    bool getCurrentState

    Authority always returns the space relative transform position (whether true or false).
    Non-authority:
    When false (default): returns the space relative transform position.
    When true: returns the authority position from the most recent state update.

    Returns
    Type Description
    Vector3

    Vector3

    Remarks
    • If InLocalSpace is true then it returns the transform.localPosition.
    • If InLocalSpace is false then it returns the transform.position.
    • When invoked on the non-authority side:If getCurrentState is true then it will return the most current authority position from the most recent state update. This can be useful if interpolation is enabled and you need to determine the final target position.
    • When invoked on the authority side:It will always return the space relative position.

    GetSpaceRelativeRotation(bool)

    Helper method that returns the space relative rotation of the transform.

    Declaration
    public Quaternion GetSpaceRelativeRotation(bool getCurrentState = false)
    Parameters
    Type Name Description
    bool getCurrentState

    Authority always returns the space relative transform rotation (whether true or false).
    Non-authority:
    When false (default): returns the space relative transform rotation.
    When true: returns the authority rotation from the most recent state update.

    Returns
    Type Description
    Quaternion

    Quaternion

    Remarks
    • If InLocalSpace is true then it returns the transform.localRotation.
    • If InLocalSpace is false then it returns the transform.rotation.
    • When invoked on the non-authority side:If getCurrentState is true then it will return the most current authority position from the most recent state update. This can be useful if interpolation is enabled and you need to determine the final target rotation.
    • When invoked on the authority side:It will always return the space relative rotation.

    GetStateId(ref NetworkTransformState)

    Declaration
    protected int GetStateId(ref NetworkTransform.NetworkTransformState state)
    Parameters
    Type Name Description
    NetworkTransform.NetworkTransformState state
    Returns
    Type Description
    int

    GetTickLatency()

    Returns the number of ticks (fractional) a client is latent relative to its current averaged RTT.

    Declaration
    public static float GetTickLatency()
    Returns
    Type Description
    float

    Returns the tick latency and local offset in seconds and as a float value.

    Remarks

    Only valid on clients.

    GetTickLatencyInSeconds()

    Returns the tick latency in seconds (typically fractional)

    Declaration
    public static float GetTickLatencyInSeconds()
    Returns
    Type Description
    float

    Returns the current tick latency in seconds as a float value.

    Initialize()

    Initializes NetworkTransform when spawned and ownership changes.

    Declaration
    protected void Initialize()

    InternalOnNetworkPostSpawn()

    For dynamically spawned NetworkObjects, when the non-authority instance's client is already connected and the SynchronizeState is still pending synchronization then we want to finalize the synchornization at this time.

    Declaration
    protected override void InternalOnNetworkPostSpawn()
    Overrides
    NetworkBehaviour.InternalOnNetworkPostSpawn()

    InternalOnNetworkSessionSynchronized()

    Handle applying the synchronization state once everything has spawned. The first NetowrkTransform handles invoking this on any other nested NetworkTransform.

    Declaration
    protected override void InternalOnNetworkSessionSynchronized()
    Overrides
    NetworkBehaviour.InternalOnNetworkSessionSynchronized()

    IsServerAuthoritative()

    Method to determine if this NetworkTransform instance is owner or server authoritative.

    Declaration
    public bool IsServerAuthoritative()
    Returns
    Type Description
    bool

    true or false

    Remarks

    When using a DistributedAuthority NetworkTopology, this will always be viewed as a Owner authoritative motion model.

    OnAuthorityPushTransformState(ref NetworkTransformState)

    Invoked just prior to being pushed to non-authority instances.

    Declaration
    protected virtual void OnAuthorityPushTransformState(ref NetworkTransform.NetworkTransformState networkTransformState)
    Parameters
    Type Name Description
    NetworkTransform.NetworkTransformState networkTransformState

    the state being pushed

    Remarks

    This is useful to know the exact position, rotation, or scale values sent to non-authoritative instances. This is only invoked on the authoritative instance.

    OnBeforeUpdateTransformState()

    Virtual method that is invoked on the non-authority side when a state update has been recieved but not yet applied.

    Declaration
    protected virtual void OnBeforeUpdateTransformState()

    OnDestroy()

    Invoked when the GameObject the NetworkBehaviour is attached to is destroyed. If you override this, you must always invoke the base class version of this OnDestroy() method.

    Declaration
    public override void OnDestroy()
    Overrides
    NetworkBehaviour.OnDestroy()

    OnFixedUpdate()

    When paired with a NetworkRigidbody and NetworkRigidbody.UseRigidBodyForMotion is enabled, this will be invoked during NetworkRigidbody.FixedUpdate.

    Declaration
    public virtual void OnFixedUpdate()

    OnGainedOwnership()

    In client-server contexts, this method is invoked on both the server and the local client of the owner when NetworkObject ownership is assigned. In distributed authority contexts, this method is invoked on all clients connected to the session.

    Declaration
    public override void OnGainedOwnership()
    Overrides
    NetworkBehaviour.OnGainedOwnership()

    OnInitialize(ref NetworkTransformState)

    Invoked when first spawned and when ownership changes.

    Declaration
    protected virtual void OnInitialize(ref NetworkTransform.NetworkTransformState replicatedState)
    Parameters
    Type Name Description
    NetworkTransform.NetworkTransformState replicatedState

    the current NetworkTransform.NetworkTransformState after initializing

    OnInitialize(ref NetworkVariable<NetworkTransformState>)

    This method is only invoked by the owner Use: OnInitialize(ref NetworkTransformState replicatedState) to be notified on all instances

    Declaration
    protected virtual void OnInitialize(ref NetworkVariable<NetworkTransform.NetworkTransformState> replicatedState)
    Parameters
    Type Name Description
    NetworkVariable<NetworkTransform.NetworkTransformState> replicatedState

    The NetworkVariable containing the NetworkTransform.NetworkTransformState

    OnIsServerAuthoritative()

    Determines whether the NetworkTransform is Server or Owner based on the AuthorityMode property. You can override this method to control this logic.

    Declaration
    protected virtual bool OnIsServerAuthoritative()
    Returns
    Type Description
    bool

    true or false

    OnLostOwnership()

    In client-server contexts, this method is invoked on the local client when it loses ownership of the associated NetworkObject and on the server when any client loses ownership. In distributed authority contexts, this method is invoked on all clients connected to the session.

    Declaration
    public override void OnLostOwnership()
    Overrides
    NetworkBehaviour.OnLostOwnership()

    OnNetworkDespawn()

    Gets called when the NetworkObject gets despawned. This method runs both client and server side.

    Declaration
    public override void OnNetworkDespawn()
    Overrides
    NetworkBehaviour.OnNetworkDespawn()

    OnNetworkObjectParentChanged(NetworkObject)

    Gets called when the parent NetworkObject of this NetworkBehaviour's NetworkObject has changed.

    Declaration
    public override void OnNetworkObjectParentChanged(NetworkObject parentNetworkObject)
    Parameters
    Type Name Description
    NetworkObject parentNetworkObject

    the new NetworkObject parent

    Overrides
    NetworkBehaviour.OnNetworkObjectParentChanged(NetworkObject)
    Remarks

    When not using a NetworkRigidbody and using an owner authoritative motion model, you can
    improve parenting transitions into and out of world and local space by:

    • Disabling SyncOwnerTransformWhenParented
    • Enabling AllowOwnerToParent
    • Enabling SwitchTransformSpaceWhenParented
      -- Note: This handles changing from world space to local space for you.
      When these settings are applied, transitioning from:
    • World space to local space (root-null parent/null to NetworkObject parent)
    • Local space back to world space (NetworkObject parent to root-null parent)
    • Local space to local space (NetworkObject parent to NetworkObject parent) Will all smoothly transition while interpolation is enabled. (Does not work if using a Rigidbody or Rigidbody2D for motion)

    When a parent changes, non-authoritative instances should:

    • Apply the resultant position, rotation, and scale from the parenting action.
    • Clear interpolators (even if not enabled on this frame)
    • Reset the interpolators to the position, rotation, and scale resultant values.
      This prevents interpolation visual anomalies and issues during initial synchronization

    OnNetworkSpawn()

    Gets called when the NetworkObject gets spawned, message handlers are ready to be registered, and the network is set up.

    Declaration
    public override void OnNetworkSpawn()
    Overrides
    NetworkBehaviour.OnNetworkSpawn()

    OnNetworkTransformStateUpdated(ref NetworkTransformState, ref NetworkTransformState)

    Invoked on the non-authoritative side when the NetworkTransformState has been updated

    Declaration
    protected virtual void OnNetworkTransformStateUpdated(ref NetworkTransform.NetworkTransformState oldState, ref NetworkTransform.NetworkTransformState newState)
    Parameters
    Type Name Description
    NetworkTransform.NetworkTransformState oldState

    the previous NetworkTransform.NetworkTransformState

    NetworkTransform.NetworkTransformState newState

    the new NetworkTransform.NetworkTransformState

    OnOwnershipChanged(ulong, ulong)

    Invoked on all clients. Override this method to be notified of any ownership changes (even if the instance was neither the previous or newly assigned current owner).

    Declaration
    protected override void OnOwnershipChanged(ulong previous, ulong current)
    Parameters
    Type Name Description
    ulong previous

    the previous owner

    ulong current

    the current owner

    Overrides
    NetworkBehaviour.OnOwnershipChanged(ulong, ulong)

    OnSynchronize<T>(ref BufferSerializer<T>)

    Override this method if your derived NetworkBehaviour requires custom synchronization data. Use of this method is only for the initial client synchronization of NetworkBehaviours and will increase the payload size for client synchronization and dynamically spawned NetworkObjects.

    Declaration
    protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer) where T : IReaderWriter
    Parameters
    Type Name Description
    BufferSerializer<T> serializer

    The serializer to use to read and write the data.

    Type Parameters
    Name Description
    T

    Either BufferSerializerReader or BufferSerializerWriter, depending whether the serializer is in read mode or write mode.

    Overrides
    NetworkBehaviour.OnSynchronize<T>(ref BufferSerializer<T>)
    Remarks

    When serializing (writing), this method is invoked during the client synchronization period and when spawning new NetworkObjects. When deserializing (reading), this method is invoked prior to the NetworkBehaviour's associated NetworkObject being spawned.

    OnTransformUpdated()

    Virtual method invoked on the non-authority side after a new state has been received and applied.

    Declaration
    protected virtual void OnTransformUpdated()

    OnUpdate()

    Declaration
    public virtual void OnUpdate()
    Remarks

    If you override this method, be sure that:

    • Non-authority always invokes this base class method.

    SetMaxInterpolationBound(float)

    Will set the maximum interpolation boundary for the interpolators of this NetworkTransform instance. This value roughly translates to the maximum value of 't' in Lerp(Vector3, Vector3, float) and Lerp(Quaternion, Quaternion, float) for all transform elements being monitored by NetworkTransform (i.e. Position, Scale, and Rotation)

    Declaration
    public void SetMaxInterpolationBound(float maxInterpolationBound)
    Parameters
    Type Name Description
    float maxInterpolationBound

    Maximum time boundary that can be used in a frame when interpolating between two values

    Remarks

    All of three max interpolation time properties will have this maximum interpolation bound value applied:

    • PositionMaxInterpolationTime
    • RotationMaxInterpolationTime
    • ScaleMaxInterpolationTime

    SetState(Vector3?, Quaternion?, Vector3?, bool)

    Directly sets a state on the authoritative transform. Owner clients can directly set the state on a server authoritative transform This will override any changes made previously to the transform This isn't resistant to network jitter. Server side changes due to this method won't be interpolated. The parameters are broken up into pos / rot / scale on purpose so that the caller can perturb just the desired one(s)

    Declaration
    public void SetState(Vector3? posIn = null, Quaternion? rotIn = null, Vector3? scaleIn = null, bool teleportDisabled = true)
    Parameters
    Type Name Description
    Vector3? posIn

    new position to move to. Can be null

    Quaternion? rotIn

    new rotation to rotate to. Can be null

    Vector3? scaleIn

    new scale to scale to. Can be null

    bool teleportDisabled

    When true (the default) the NetworkObject will not be teleported and, if enabled, will interpolate. When false the NetworkObject will teleport/apply the parameters provided immediately.

    Exceptions
    Type Condition
    Exception

    Thrown when the function is called on non-spawned object or, when it's called without proper authority

    Teleport(Vector3, Quaternion, Vector3)

    Teleport an already spawned object to the given values without interpolating.

    Declaration
    public void Teleport(Vector3 newPosition, Quaternion newRotation, Vector3 newScale)
    Parameters
    Type Name Description
    Vector3 newPosition

    new position to move to.

    Quaternion newRotation

    new rotation to rotate to.

    Vector3 newScale

    new scale to scale to.

    Remarks

    This is intended to be used on already spawned objects, for setting the position of a dynamically spawned object just apply the transform values prior to spawning.
    With player objects, override the OnNetworkSpawn() method and have the authority make adjustments to the transform prior to invoking base.OnNetworkSpawn.

    Exceptions
    Type Condition
    Exception

    Thrown when called from a non-authoritative context (client without ownership)


    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Fields
      • AuthorityMode
      • AutoOwnerAuthorityTickOffset
      • InLocalSpace
      • Interpolate
      • InterpolationBufferTickOffset
      • OnClientRequestChange
      • PositionInterpolationType
      • PositionLerpSmoothing
      • PositionMaxInterpolationTime
      • PositionThreshold
      • PositionThresholdDefault
      • RotAngleThreshold
      • RotAngleThresholdDefault
      • RotationInterpolationType
      • RotationLerpSmoothing
      • RotationMaxInterpolationTime
      • ScaleInterpolationType
      • ScaleLerpSmoothing
      • ScaleMaxInterpolationTime
      • ScaleThreshold
      • ScaleThresholdDefault
      • SlerpPosition
      • SwitchTransformSpaceWhenParented
      • SyncPositionX
      • SyncPositionY
      • SyncPositionZ
      • SyncRotAngleX
      • SyncRotAngleY
      • SyncRotAngleZ
      • SyncScaleX
      • SyncScaleY
      • SyncScaleZ
      • TickSyncChildren
      • UseHalfFloatPrecision
      • UseQuaternionCompression
      • UseQuaternionSynchronization
      • UseUnreliableDeltas
      • m_AddLogEntry
      • m_CachedNetworkManager
    • Properties
      • CanCommitToTransform
      • PositionInLocalSpace
      • RotationInLocalSpace
    • Methods
      • ApplyAuthoritativeState()
      • Awake()
      • GetHalfPositionState()
      • GetScale(bool)
      • GetSpaceRelativePosition(bool)
      • GetSpaceRelativeRotation(bool)
      • GetStateId(ref NetworkTransformState)
      • GetTickLatency()
      • GetTickLatencyInSeconds()
      • Initialize()
      • InternalOnNetworkPostSpawn()
      • InternalOnNetworkSessionSynchronized()
      • IsServerAuthoritative()
      • OnAuthorityPushTransformState(ref NetworkTransformState)
      • OnBeforeUpdateTransformState()
      • OnDestroy()
      • OnFixedUpdate()
      • OnGainedOwnership()
      • OnInitialize(ref NetworkTransformState)
      • OnInitialize(ref NetworkVariable<NetworkTransformState>)
      • OnIsServerAuthoritative()
      • OnLostOwnership()
      • OnNetworkDespawn()
      • OnNetworkObjectParentChanged(NetworkObject)
      • OnNetworkSpawn()
      • OnNetworkTransformStateUpdated(ref NetworkTransformState, ref NetworkTransformState)
      • OnOwnershipChanged(ulong, ulong)
      • OnSynchronize<T>(ref BufferSerializer<T>)
      • OnTransformUpdated()
      • OnUpdate()
      • SetMaxInterpolationBound(float)
      • SetState(Vector3?, Quaternion?, Vector3?, bool)
      • Teleport(Vector3, Quaternion, Vector3)
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)