docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class AnticipatedNetworkTransform

    A subclass of NetworkTransform that supports basic client anticipation - the client can set a value on the belief that the server will update it to reflect the same value in a future update (i.e., as the result of an RPC call). This value can then be adjusted as new updates from the server come in, in three basic modes:

    • Snap: In this mode (with StaleDataHandling set to Ignore and no OnReanticipate(double) callback), the moment a more up-to-date value is received from the authority, it will simply replace the anticipated value, resulting in a "snap" to the new value if it is different from the anticipated value.
    • Smooth: In this mode (with StaleDataHandling set to Ignore and an OnReanticipate(double) callback that calls Smooth(TransformState, TransformState, float) from the anticipated value to the authority value with an appropriate Lerp(float, float, float)-style smooth function), when a more up-to-date value is received from the authority, it will interpolate over time from an incorrect anticipated value to the correct authoritative value.
    • Constant Reanticipation: In this mode (with StaleDataHandling set to Reanticipate and an OnReanticipate(double) that calculates a new anticipated value based on the current authoritative value), when a more up-to-date value is received from the authority, user code calculates a new anticipated value, possibly calling Smooth(TransformState, TransformState, float) to interpolate between the previous anticipation and the new anticipation. This is useful for values that change frequently and need to constantly be re-evaluated, as opposed to values that change only in response to user action and simply need a one-time anticipation when the user performs that action.

    Note that these three modes may be combined. For example, if an OnReanticipate(double) callback does not call either Smooth(TransformState, TransformState, float) or one of the Anticipate methods, the result will be a snap to the authoritative value, enabling for a callback that may conditionally call Smooth(TransformState, TransformState, float) when the difference between the anticipated and authoritative values is within some threshold, but fall back to snap behavior if the difference is too large.

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    NetworkBehaviour
    NetworkTransform
    AnticipatedNetworkTransform
    Inherited Members
    NetworkTransform.PositionThresholdDefault
    NetworkTransform.RotAngleThresholdDefault
    NetworkTransform.ScaleThresholdDefault
    NetworkTransform.OnClientRequestChange
    NetworkTransform.UseUnreliableDeltas
    NetworkTransform.SyncPositionX
    NetworkTransform.SyncPositionY
    NetworkTransform.SyncPositionZ
    NetworkTransform.SyncRotAngleX
    NetworkTransform.SyncRotAngleY
    NetworkTransform.SyncRotAngleZ
    NetworkTransform.SyncScaleX
    NetworkTransform.SyncScaleY
    NetworkTransform.SyncScaleZ
    NetworkTransform.PositionThreshold
    NetworkTransform.RotAngleThreshold
    NetworkTransform.ScaleThreshold
    NetworkTransform.UseQuaternionSynchronization
    NetworkTransform.UseQuaternionCompression
    NetworkTransform.UseHalfFloatPrecision
    NetworkTransform.InLocalSpace
    NetworkTransform.Interpolate
    NetworkTransform.SlerpPosition
    NetworkTransform.CanCommitToTransform
    NetworkTransform.m_CachedIsServer
    NetworkTransform.m_CachedNetworkManager
    NetworkTransform.GetSpaceRelativePosition(bool)
    NetworkTransform.GetSpaceRelativeRotation(bool)
    NetworkTransform.GetScale(bool)
    NetworkTransform.m_AddLogEntry
    NetworkTransform.GetStateId(ref NetworkTransform.NetworkTransformState)
    NetworkTransform.GetHalfPositionState()
    NetworkTransform.TryCommitTransformToServer(Transform, double)
    NetworkTransform.OnAuthorityPushTransformState(ref NetworkTransform.NetworkTransformState)
    NetworkTransform.ApplyAuthoritativeState()
    NetworkTransform.SetMaxInterpolationBound(float)
    NetworkTransform.Awake()
    NetworkTransform.OnLostOwnership()
    NetworkTransform.OnGainedOwnership()
    NetworkTransform.OnOwnershipChanged(ulong, ulong)
    NetworkTransform.OnInitialize(ref NetworkTransform.NetworkTransformState)
    NetworkTransform.OnInitialize(ref NetworkVariable<NetworkTransform.NetworkTransformState>)
    NetworkTransform.Initialize()
    NetworkTransform.OnNetworkObjectParentChanged(NetworkObject)
    NetworkTransform.SetState(Vector3?, Quaternion?, Vector3?, bool)
    NetworkTransform.Teleport(Vector3, Quaternion, Vector3)
    NetworkTransform.OnIsServerAuthoritative()
    NetworkTransform.IsServerAuthoritative()
    NetworkBehaviour.__rpc_func_table
    NetworkBehaviour.__rpc_name_table
    NetworkBehaviour.__rpc_exec_stage
    NetworkBehaviour.NetworkVariableFields
    NetworkBehaviour.__getTypeName()
    NetworkBehaviour.__beginSendServerRpc(uint, ServerRpcParams, RpcDelivery)
    NetworkBehaviour.__endSendServerRpc(ref FastBufferWriter, uint, ServerRpcParams, RpcDelivery)
    NetworkBehaviour.__beginSendClientRpc(uint, ClientRpcParams, RpcDelivery)
    NetworkBehaviour.__endSendClientRpc(ref FastBufferWriter, uint, ClientRpcParams, RpcDelivery)
    NetworkBehaviour.__beginSendRpc(uint, RpcParams, RpcAttribute.RpcAttributeParams, SendTo, RpcDelivery)
    NetworkBehaviour.__endSendRpc(ref FastBufferWriter, uint, RpcParams, RpcAttribute.RpcAttributeParams, SendTo, RpcDelivery)
    NetworkBehaviour.__createNativeList<T>()
    NetworkBehaviour.GetNetworkBehaviour(ushort)
    NetworkBehaviour.OnNetworkPreSpawn(ref NetworkManager)
    NetworkBehaviour.OnNetworkPostSpawn()
    NetworkBehaviour.OnNetworkSessionSynchronized()
    NetworkBehaviour.OnInSceneObjectsSpawned()
    NetworkBehaviour.__initializeVariables()
    NetworkBehaviour.__initializeRpcs()
    NetworkBehaviour.__registerRpc(uint, NetworkBehaviour.RpcReceiveHandler, string)
    NetworkBehaviour.__nameNetworkVariable(NetworkVariableBase, string)
    NetworkBehaviour.GetNetworkObject(ulong)
    NetworkBehaviour.OnReanticipate(double)
    NetworkBehaviour.NetworkManager
    NetworkBehaviour.RpcTarget
    NetworkBehaviour.IsLocalPlayer
    NetworkBehaviour.IsOwner
    NetworkBehaviour.IsServer
    NetworkBehaviour.ServerIsHost
    NetworkBehaviour.IsClient
    NetworkBehaviour.IsHost
    NetworkBehaviour.IsOwnedByServer
    NetworkBehaviour.IsSpawned
    NetworkBehaviour.NetworkObject
    NetworkBehaviour.HasNetworkObject
    NetworkBehaviour.NetworkObjectId
    NetworkBehaviour.NetworkBehaviourId
    NetworkBehaviour.OwnerClientId
    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.useGUILayout
    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.CompareTag(string)
    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.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    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.Components.dll
    Syntax
    [DisallowMultipleComponent]
    [AddComponentMenu("Netcode/Anticipated Network Transform")]
    [DefaultExecutionOrder(100000)]
    public class AnticipatedNetworkTransform : NetworkTransform

    Fields

    StaleDataHandling

    Defines what the behavior should be if we receive a value from the server with an earlier associated time value than the anticipation time value.

    If this is Ignore, the stale data will be ignored and the authoritative value will not replace the anticipated value until the anticipation time is reached. OnAuthoritativeValueChanged and OnReanticipate will also not be invoked for this stale data.

    If this is Reanticipate, the stale data will replace the anticipated data and OnAuthoritativeValueChanged and OnReanticipate will be invoked. In this case, the authoritativeTime value passed to OnReanticipate will be lower than the anticipationTime value, and that callback can be used to calculate a new anticipated value.

    Declaration
    public StaleDataHandling StaleDataHandling
    Field Value
    Type Description
    StaleDataHandling

    Properties

    AnticipatedState

    Contains the current anticipated state, which will match the values of this object's actual MonoBehaviour.transform. When a server update arrives, this value will be overwritten by the new server value (unless stale data handling is set to "Ignore" and the update is determined to be stale). This value will be duplicated in PreviousAnticipatedState, which will NOT be overwritten in server updates.

    Declaration
    public AnticipatedNetworkTransform.TransformState AnticipatedState { get; }
    Property Value
    Type Description
    AnticipatedNetworkTransform.TransformState

    AuthoritativeState

    Contains the current state of this transform on the server side. Note that, on the server side, this gets updated at the end of the frame, and will not immediately reflect changes to the transform.

    Declaration
    public AnticipatedNetworkTransform.TransformState AuthoritativeState { get; }
    Property Value
    Type Description
    AnticipatedNetworkTransform.TransformState

    PreviousAnticipatedState

    Holds the most recent anticipated state, whatever was most recently set using the Anticipate methods. Unlike AnticipatedState, this does not get overwritten when a server update arrives.

    Declaration
    public AnticipatedNetworkTransform.TransformState PreviousAnticipatedState { get; }
    Property Value
    Type Description
    AnticipatedNetworkTransform.TransformState

    ShouldReanticipate

    Indicates whether this transform currently needs reanticipation. If this is true, the anticipated value has been overwritten by the authoritative value from the server; the previous anticipated value is stored in PreviousAnticipatedState

    Declaration
    public bool ShouldReanticipate { get; }
    Property Value
    Type Description
    bool

    Methods

    AnticipateMove(Vector3)

    Anticipate that, at the end of one round trip to the server, this transform will be in the given newPosition

    Declaration
    public void AnticipateMove(Vector3 newPosition)
    Parameters
    Type Name Description
    Vector3 newPosition

    AnticipateRotate(Quaternion)

    Anticipate that, at the end of one round trip to the server, this transform will have the given newRotation

    Declaration
    public void AnticipateRotate(Quaternion newRotation)
    Parameters
    Type Name Description
    Quaternion newRotation

    AnticipateScale(Vector3)

    Anticipate that, at the end of one round trip to the server, this transform will have the given newScale

    Declaration
    public void AnticipateScale(Vector3 newScale)
    Parameters
    Type Name Description
    Vector3 newScale

    AnticipateState(TransformState)

    Anticipate that, at the end of one round trip to the server, the transform will have the given newState

    Declaration
    public void AnticipateState(AnticipatedNetworkTransform.TransformState newState)
    Parameters
    Type Name Description
    AnticipatedNetworkTransform.TransformState newState

    OnBeforeUpdateTransformState()

    Declaration
    protected override void OnBeforeUpdateTransformState()
    Overrides
    NetworkTransform.OnBeforeUpdateTransformState()

    OnDestroy()

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

    OnNetworkDespawn()

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

    OnNetworkSpawn()

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

    OnNetworkTransformStateUpdated(ref NetworkTransformState, ref NetworkTransformState)

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

    Declaration
    protected override 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

    Overrides
    NetworkTransform.OnNetworkTransformStateUpdated(ref NetworkTransform.NetworkTransformState, ref NetworkTransform.NetworkTransformState)

    OnSynchronize<T>(ref BufferSerializer<T>)

    This is invoked when a new client joins (server and client sides) Server Side: Serializes as if we were teleporting (everything is sent via NetworkTransformState) Client Side: Adds the interpolated state which applies the NetworkTransformState as well

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

    If a derived class overrides this, then make sure to invoke this base method!

    OnTransformUpdated()

    Declaration
    protected override void OnTransformUpdated()
    Overrides
    NetworkTransform.OnTransformUpdated()

    Smooth(TransformState, TransformState, float)

    Interpolate between the transform represented by from to the transform represented by to over durationSeconds of real time. The duration uses deltaTime, so it is affected by timeScale.

    Declaration
    public void Smooth(AnticipatedNetworkTransform.TransformState from, AnticipatedNetworkTransform.TransformState to, float durationSeconds)
    Parameters
    Type Name Description
    AnticipatedNetworkTransform.TransformState from
    AnticipatedNetworkTransform.TransformState to
    float durationSeconds

    Update()

    Declaration
    protected override void Update()
    Overrides
    NetworkTransform.Update()
    Remarks

    If you override this method, be sure that:

    • Non-authority always invokes this base class method.
    In This Article
    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)