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.AuthorityMode
    NetworkTransform.TickSyncChildren
    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.SwitchTransformSpaceWhenParented
    NetworkTransform.PositionInLocalSpace
    NetworkTransform.RotationInLocalSpace
    NetworkTransform.Interpolate
    NetworkTransform.SlerpPosition
    NetworkTransform.CanCommitToTransform
    NetworkTransform.m_CachedNetworkManager
    NetworkTransform.GetSpaceRelativePosition(bool)
    NetworkTransform.GetSpaceRelativeRotation(bool)
    NetworkTransform.GetScale(bool)
    NetworkTransform.m_AddLogEntry
    NetworkTransform.GetStateId(ref NetworkTransform.NetworkTransformState)
    NetworkTransform.GetHalfPositionState()
    NetworkTransform.OnSynchronize<T>(ref BufferSerializer<T>)
    NetworkTransform.OnAuthorityPushTransformState(ref NetworkTransform.NetworkTransformState)
    NetworkTransform.ApplyAuthoritativeState()
    NetworkTransform.SetMaxInterpolationBound(float)
    NetworkTransform.Awake()
    NetworkTransform.OnInitialize(ref NetworkTransform.NetworkTransformState)
    NetworkTransform.OnInitialize(ref NetworkVariable<NetworkTransform.NetworkTransformState>)
    NetworkTransform.Initialize()
    NetworkTransform.OnLostOwnership()
    NetworkTransform.OnGainedOwnership()
    NetworkTransform.OnOwnershipChanged(ulong, ulong)
    NetworkTransform.OnNetworkObjectParentChanged(NetworkObject)
    NetworkTransform.SetState(Vector3?, Quaternion?, Vector3?, bool)
    NetworkTransform.Teleport(Vector3, Quaternion, Vector3)
    NetworkTransform.OnFixedUpdate()
    NetworkTransform.OnIsServerAuthoritative()
    NetworkTransform.IsServerAuthoritative()
    NetworkTransform.GetTickLatency()
    NetworkTransform.GetTickLatencyInSeconds()
    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.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Scene)
    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/Anticipated Network Transform")]
    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

    InternalOnNetworkPostSpawn()

    (This replaces the any subsequent OnSynchronize for NetworkTransforms post client synchronization) This occurs on already connected clients when dynamically spawning a NetworkObject for non-authoritative instances.

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

    InternalOnNetworkSessionSynchronized()

    (This replaces the first OnSynchronize for NetworkTransforms) This is needed to initialize when fully synchronized since non-authority instances don't apply the initial synchronization (new client synchronization) until after everything has been spawned and synchronized.

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

    OnBeforeUpdateTransformState()

    Declaration
    protected override void OnBeforeUpdateTransformState()
    Overrides
    NetworkTransform.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
    NetworkTransform.OnDestroy()

    OnNetworkDespawn()

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

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

    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
    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)

    OnTransformUpdated()

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

    OnUpdate()

    Declaration
    public override void OnUpdate()
    Overrides
    NetworkTransform.OnUpdate()
    Remarks

    If you override this method, be sure that:

    • Non-authority always invokes this base class method.

    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
    In This Article
    • Fields
      • StaleDataHandling
    • Properties
      • AnticipatedState
      • AuthoritativeState
      • PreviousAnticipatedState
      • ShouldReanticipate
    • Methods
      • AnticipateMove(Vector3)
      • AnticipateRotate(Quaternion)
      • AnticipateScale(Vector3)
      • AnticipateState(TransformState)
      • InternalOnNetworkPostSpawn()
      • InternalOnNetworkSessionSynchronized()
      • OnBeforeUpdateTransformState()
      • OnDestroy()
      • OnNetworkDespawn()
      • OnNetworkSpawn()
      • OnNetworkTransformStateUpdated(ref NetworkTransformState, ref NetworkTransformState)
      • OnTransformUpdated()
      • OnUpdate()
      • Smooth(TransformState, TransformState, float)
    Back to top
    Copyright © 2024 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)