Photon Fusion 1.1.9

Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Attributes | Properties | List of all members
NetworkTransform Class Reference

Replicates a Unity Transform's position and rotation states from the NetworkObject.StateAuthority to all other peers. Add this component to a GameObject to sync the position and rotation data. A NetworkObject is required on this GameObject or a parent of this GameObject. More...

Inherits IAfterTick, IPredictedSpawnBehaviour, and NetworkPositionRotation.

Inherited by NetworkRigidbodyBase.

Classes

struct  InterpolatedTransformParameters
 Struct that provides relevant parameters when interpolating a view representation with position and rotation data between two known states, referred as 'From' and 'To'. More...
 

Public Member Functions

override void AfterAllTicks (bool resimulation, int tickCount)
 Implements IAfterAllTicks. If overriding this method in an inheritor, the base method should be called. To extend the functionality of copying data from the engine to the networked buffer, override and extend CopyFromEngineToBuffer instead.
 
void AfterTick ()
 Implements IAfterTick. If overriding this method in an inheritor, the base method should be called.
 
override void BeforeUpdate ()
 Overrides NetworkPositionRotation.BeforeUpdate. If overriding this method in an inheritor, the base method should be called.
 
override void CopyBackingFieldsToState (bool firstTime)
 Implements NetworkBehaviour.CopyBackingFieldsToState. If overriding this method in an inheritor, the base method should be called.
 
override void Despawned (NetworkRunner runner, bool hasState)
 Called before the network object is despawned.
 
void PredictedSpawnCacheTransformState ()
 If this object is a predicted spawn, caches the current transform state for interpolated rendering and prediction error correction.
 
virtual void PredictedSpawnFailed ()
 Implements IPredictedSpawnBehaviour.PredictedSpawnFailed and does nothing by default.
 
virtual void PredictedSpawnRender ()
 Implements IPredictedSpawnBehaviour.PredictedSpawnSpawned. If overriding this method in an inheritor, the base method should be called.
 
virtual void PredictedSpawnSpawned ()
 Implements IPredictedSpawnBehaviour.PredictedSpawnSpawned. If overriding this method in an inheritor, the base method should be called.
 
virtual void PredictedSpawnSuccess ()
 Implements IPredictedSpawnBehaviour.PredictedSpawnSuccess and does nothing by default.
 
virtual void PredictedSpawnUpdate ()
 Implements IPredictedSpawnBehaviour.PredictedSpawnUpdate and, by default, calls PredictedSpawnCacheTransformState. Behaviours that change the Transform state of this predict-spawned object should either be ordered before NetworkTransform or call PredictedSpawnCacheTransformState after doing so. If overriding this method in an inheritor, the base method should be called.
 
Vector3 ReadTeleportInterpolationAngularVelocity ()
 Reads from this object's networked data field holding the interpolation angular velocity (used on position teleports) using the default Runner position read accuracy. See TeleportToRotation for more information on how this value is used.
 
Vector3 ReadTeleportInterpolationAngularVelocity (int *ptr)
 Reads from a field holding the interpolation angular velocity (used on position teleports) from the networked data pointed by ptr using the default Runner position read accuracy. See TeleportToRotation for more information on how this value is used.
 
Vector3 ReadTeleportInterpolationVelocity ()
 Reads from this object's networked data field holding the interpolation velocity (used on position teleports) using the default Runner position read accuracy. See TeleportToPosition for more information on how this value is used.
 
Vector3 ReadTeleportInterpolationVelocity (int *ptr)
 Reads from a field holding the interpolation velocity (used on position teleports) from the networked data pointed by ptr using the default Runner position read accuracy. See TeleportToPosition for more information on how this value is used.
 
bool ReadTeleportPositionInterpolateBackwards ()
 Reads from this object's field holding information about the last TeleportToPosition call and if should be interpolated forward (emulated To based on From state + interpolation) or backwards (Emulated From based on To state - interpolation).
 
int ReadTeleportPositionTick ()
 Reads from this object's field holding the tick number where TeleportToPosition was last called.
 
bool ReadTeleportRotationInterpolateBackwards ()
 Reads from this object's field holding information about the last TeleportToRotation call and if should be interpolated forward (emulated To based on From state + interpolation) or backwards (Emulated From based on To state - interpolation).
 
int ReadTeleportRotationTick ()
 Reads from this object's field holding the tick number where TeleportToRotation was last called.
 
override void Render ()
 Overrides SimulationBehaviour.Render, computing the interpolated position and rotation values according to the NetworkBehaviour.InterpolationDataSource, updating the prediction error correction and calling ApplyInterpolatedTransform to apply the results to the InterpolationTarget.
 
override void Spawned ()
 Overrides NetworkBehaviour.Spawned. If overriding this method in an inheritor, the base method should be called.
 
void TeleportToPosition (Vector3 position, Vector3? interpolationVel=null, bool interpolateBackwards=true)
 Teleports the object to the provided position while making the networked state aware that the object was teleported and the view interpolation needs special handling. The position is immediately set to the transform's position field and additional data is stored in order to interpolate the view object between the ticks. While interpolating the visual representation of the networked object TO a tick where a teleport happened, the object's latest state (tick when the teleport is performed) will not be used, as doing so would cause the interpolation target to visually interpolate along the teleported distance. Instead, the view will be interpolated between the FROM state (tick before the teleport) and an artificial position computed based on this FROM state and an interpolation velocity (see interpolationVel ), in order to emulate how the object would behave if the teleport had not been performed.
 
void TeleportToPositionRotation (Vector3 position, Quaternion rotation, Vector3? interpolationVel=null, Vector3? interpolationAngularVel=null, bool interpolateBackwards=true)
 Teleports the object to the provided position and rotation while making the networked state aware that the object was teleported and the view interpolation needs special handling. The rotation is immediately set to the transform's rotation field and additional data is stored in order to interpolate the view object between the ticks. See TeleportToPosition and TeleportToRotation for more details about why and how the special interpolation handling is performed.
 
void TeleportToRotation (Quaternion rotation, Vector3? interpolationAngularVel=null, bool interpolateBackwards=true)
 Teleports the object to the provided rotation while making the networked state aware that the object was teleported and the view interpolation needs special handling. The rotation is immediately set to the transform's rotation field and additional data is stored in order to interpolate the view object between the ticks. While interpolating the visual representation of the networked object TO a tick where a teleport happened, the object's latest state (tick when the teleport is performed) will not be used, as doing so would cause the interpolation target to visually interpolate along the teleported rotation. Instead, the view will be interpolated between the FROM state (tick before the teleport) and an artificial rotation computed based on this FROM state and an interpolation angular velocity (see interpolationAngularVel ), in order to emulate how the object would behave if the teleport had not been performed.
 
void WriteTeleportInterpolationAngularVelocity (Vector3 angularVel)
 Writes to this object's networked data field holding the interpolation angular velocity (used on position teleports) using the default Runner position write accuracy. See TeleportToRotation for more information on how this value is used.
 
void WriteTeleportInterpolationAngularVelocity (Vector3 angularVel, int *ptr)
 Writes to a field holding the interpolation angular velocity (used on position teleports) on the networked data pointed by ptr using the default Runner position write accuracy. See TeleportToRotation for more information on how this value is used.
 
void WriteTeleportInterpolationVelocity (Vector3 velocity)
 Writes to this object's networked data field holding the interpolation velocity (used on position teleports) using the default Runner position write accuracy. See TeleportToPosition for more information on how this value is used.
 
void WriteTeleportInterpolationVelocity (Vector3 velocity, int *ptr)
 Writes to a field holding the interpolation velocity (used on position teleports) on the networked data pointed by ptr using the default Runner position write accuracy. See TeleportToPosition for more information on how this value is used.
 
void WriteTeleportPositionInterpolateBackwards (bool backwards)
 Writes to this object's field holding information about the last TeleportToPosition call and if should be interpolated forward (emulated To based on From state + interpolation) or backwards (Emulated From based on To state - interpolation).
 
void WriteTeleportPositionTick (int tick)
 Writes this object's field holding the tick number where TeleportToPosition was last called.
 
void WriteTeleportRotationInterpolateBackwards (bool backwards)
 Writes to this object's field holding information about the last TeleportToRotation call and if should be interpolated forward (emulated To based on From state + interpolation) or backwards (Emulated From based on To state - interpolation).
 
void WriteTeleportRotationTick (int tick)
 Writes this object's field holding the tick number where TeleportToRotation was last called.
 
void AfterTick ()
 Called after each tick simulation completes.
 
void PredictedSpawnFailed ()
 Called when Server does not produce the spawn that has been predicted. The spawn did not actually happen, and this callback may be used to clean up after the missed prediction.
 
void PredictedSpawnRender ()
 Called every tick in place of Render(), until PredictedSpawnSuccess or PredictedSpawnFailed occur.
 
void PredictedSpawnSpawned ()
 Called in place of Spawned(), when the predicted object is initially created locally on the client.
 
void PredictedSpawnSuccess ()
 Called when Server spawn was has been confirmed, and the predicted spawn object has been added to the simulation.
 
void PredictedSpawnUpdate ()
 Called every tick in place of FixedUpdateNetwork(), until PredictedSpawnSuccess or PredictedSpawnFailed occur.
 
- Public Member Functions inherited from NetworkPositionRotation
Quaternion ReadRotation ()
 Reads from the rotation field on this object's networked data with the default Runner position read accuracy.
 
Quaternion ReadRotation (int *ptr)
 Reads from a rotation field on the networked data pointed by ptr with the default Runner position read accuracy.
 
void WriteRotation (Quaternion rotation)
 Writes to a rotation field on this object's networked data with the default Runner position write accuracy.
 
void WriteRotation (Quaternion rotation, int *ptr)
 Writes to a rotation field on the networked data pointed by ptr with the default Runner position write accuracy.
 
- Public Member Functions inherited from NetworkPosition
virtual void AfterAllTicks (bool resimulation, int tickCount)
 Implements IAfterAllTicks. If overriding this method in an inheritor, the base method should be called. To extend the functionality of copying data from the engine to the networked buffer, override and extend CopyFromEngineToBuffer instead.
 
void AfterHostMigration ()
 Invoked after the Host Migration happens in order to setup non-networked data on NetworkBehaviors.
 
virtual void BeforeAllTicks (bool resimulation, int tickCount)
 Implements IBeforeAllTicks. If overriding this method in an inheritor, the base method should be called. To extend the functionality of copying data from the networked buffer to the engine, override and extend CopyFromBufferToEngine instead.
 
virtual void BeforeCopyPreviousState ()
 Implements IBeforeCopyPreviousState. If overriding this method in an inheritor, the base method should be called.
 
virtual void BeforeUpdate ()
 Implements IBeforeUpdate. If overriding this method in an inheritor, the base method should be called.
 
override void CopyBackingFieldsToState (bool firstTime)
 Implements NetworkBehaviour.CopyBackingFieldsToState. If overriding this method in an inheritor, the base method should be called.
 
Vector3 ReadPosition ()
 Reads from the position field on this object's networked data with the default Runner position read accuracy.
 
Vector3 ReadPosition (int *ptr)
 Reads from a position field on the networked data pointed by ptr with the default Runner position read accuracy.
 
virtual void RemotePrefabCreated ()
 Implements IRemotePrefabCreated. If overriding this method in an inheritor, the base method should be called.
 
override void Spawned ()
 Overrides NetworkBehaviour.Spawned. If overriding this method in an inheritor, the base method should be called.
 
void WritePosition (Vector3 position)
 Writes to a position field on this object's networked data with the default Runner position write accuracy.
 
void WritePosition (Vector3 position, int *ptr)
 Writes to a position field on the networked data pointed by ptr with the default Runner position write accuracy.
 
void BeforeUpdate ()
 Called at the start of the Fusion Update loop, before the Fusion simulation loop.
 
void BeforeAllTicks (bool resimulation, int tickCount)
 Called before the resimulation loop (when applicable), and also before the forward simulation loop. Only called on Updates where resimulation or forward ticks are processed.
 
void AfterAllTicks (bool resimulation, int tickCount)
 Called after the resimulation loop (when applicable), and also after the forward simulation loop. Only called on Updates where resimulation or forward ticks are processed.
 
void AfterHostMigration ()
 Invoked after the Host Migration happens in order to setup non-networked data on NetworkBehaviors.
 
- Public Member Functions inherited from NetworkBehaviour
virtual void CopyBackingFieldsToState (bool firstTime)
 
void CopyStateFrom (NetworkBehaviour source)
 Copies entire state of passed in source NetworkBehaviour
 
virtual void CopyStateToBackingFields ()
 
virtual void Despawned (NetworkRunner runner, bool hasState)
 Called before the network object is despawned.
 
override void FixedUpdateNetwork ()
 Fusion FixedUpdate timing callback.
 
T? GetInput< T > ()
 
bool GetInput< T > (out T input)
 Returns true if it a valid INetworkInput can be found for the current simulation tick (Typically this is used in FixedUpdateNetwork).
 
bool GetInterpolationData (out InterpolationData data, bool? predicted=null)
 Get 'To' and 'From' states, and the Alpha (t) values needed for lerping.
 
bool GetInterpolationData (out InterpolationData data, out bool predicted)
 Get 'To' and 'From' states, and the Alpha (t) values needed for interpolation.
 
RawInterpolator GetInterpolator (string propertyName)
 Get a raw interpolator for a networked property. The returned RawInterpolator provides a way to calculate the "between-ticks" value of the named [Networked] property.
 
Interpolator< T > GetInterpolator< T > (string propertyName)
 Get an interpolator for a networked property. The returned Interpolator provides a way to calculate the "between-ticks" value of the named [Networked] property with the specified type T. The value is a linear interpolation between the "from" and the "to" ticks and is available via the Value property on the Interpolator.
 
int GetLocalAuthorityMask ()
 Gets a bitmask of AuthorityMasks flags, representing the current local authority over this NetworkObject.
 
delegate int[] InterestGroupsCallback (Type type, NetworkBehaviour behaviour)
 
virtual bool IsInterpolationDataPredicted ()
 If the behaviour data should be interpolated between latest predicted states or between snapshots.
 
NetworkBehaviourCallbackReference OnChangeAdd< T > (int wordOffset, int wordCount, ChangedDelegate< T > callback, OnChangedTargets targets=OnChangedTargets.All)
 Adds a OnChange callback to this behaviour which is bound to a specific word offset and word count.
 
NetworkBehaviourCallbackReference OnChangeAdd< T > (string propertyName, ChangedDelegate< T > callback, OnChangedTargets targetses=OnChangedTargets.All)
 Adds a OnChange callback to this behaviour which is bound to a specific weaved property.
 
void OnChangeClearAll ()
 Clear all dynamic OnChange callbacks from this behaviour.
 
bool OnChangeRemove (NetworkBehaviourCallbackReference reference)
 Removes a specific OnChange callback from this behaviour.
 
virtual void Spawned ()
 Post spawn callback.
 
virtual void FixedUpdateNetwork ()
 Fusion FixedUpdate timing callback.
 
virtual void Render ()
 Post simulation frame rendering callback. Runs after all simulations have finished. Use in place of Unity's Update when Fusion is handling Physics.
 
- Public Member Functions inherited from Behaviour
AddBehaviour< T > ()
 Wrapper for Unity's GameObject.AddComponent()
 
GetBehaviour< T > ()
 Wrapper for Unity's GameObject.GetComponentInChildren()
 
bool TryGetBehaviour< T > (out T behaviour)
 Wrapper for Unity's GameObject.TryGetComponent()
 

Static Public Member Functions

static Vector3 ReadTeleportInterpolationAngularVelocity (int *ptr, ReadAccuracy readAccuracy)
 Reads from a field holding the interpolation angular velocity (used on position teleports) on the networked data pointed by ptr with the defined readAccuracy . See TeleportToRotation for more information on how this value is used.
 
static Vector3 ReadTeleportInterpolationVelocity (int *ptr, ReadAccuracy readAccuracy)
 Reads from a field holding the interpolation velocity (used on position teleports) from the networked data pointed by ptr with the defined readAccuracy . See TeleportToPosition for more information on how this value is used.
 
static bool ReadTeleportPositionInterpolateBackwards (int *ptr)
 Reads from the networked data pointer by ptr a field holding information about the last TeleportToPosition call and if should be interpolated forward (emulated To based on From state + interpolation) or backwards (Emulated From based on To state - interpolation).
 
static int ReadTeleportPositionTick (int *ptr)
 Reads from the networked data pointer by ptr a field holding the tick number where TeleportToPosition was last called.
 
static bool ReadTeleportRotationInterpolateBackwards (int *ptr)
 Reads from the networked data pointer by ptr a field holding information about the last TeleportToRotation call and if should be interpolated forward (emulated To based on From state + interpolation) or backwards (Emulated From based on To state - interpolation).
 
static int ReadTeleportRotationTick (int *ptr)
 Reads from the networked data pointer by ptr a field holding the tick number where TeleportToRotation was last called.
 
static void WriteTeleportInterpolationAngularVelocity (Vector3 angularVel, int *ptr, WriteAccuracy writeAccuracy)
 Writes to a field holding the interpolation angular velocity (used on position teleports) from the networked data pointed by ptr with the defined writeAccuracy . See TeleportToRotation for more information on how this value is used.
 
static void WriteTeleportInterpolationVelocity (Vector3 velocity, int *ptr, WriteAccuracy writeAccuracy)
 Writes to a field holding the interpolation velocity (used on position teleports) from the networked data pointed by ptr with the defined writeAccuracy . See TeleportToPosition for more information on how this value is used.
 
static void WriteTeleportPositionInterpolateBackwards (int *ptr, bool backwards)
 Writes the networked data pointer by ptr , on a field holding information about the last TeleportToPosition call and if should be interpolated forward (emulated To based on From state + interpolation) or backwards (Emulated From based on To state - interpolation).
 
static void WriteTeleportPositionTick (int tick, int *ptr)
 Writes to the networked data pointer by ptr a field holding the tick number where TeleportToPosition was last called.
 
static void WriteTeleportRotationInterpolateBackwards (int *ptr, bool backwards)
 Writes to this object's field holding information about the last TeleportToRotation call and if should be interpolated forward (emulated To based on From state + interpolation) or backwards (Emulated From based on To state - interpolation).
 
static void WriteTeleportRotationTick (int tick, int *ptr)
 Writes to the networked data pointer by ptr a field holding the tick number where TeleportToRotation was last called.
 
- Static Public Member Functions inherited from NetworkPositionRotation
static Quaternion ReadRotation (int *ptr, ReadAccuracy readAccuracy)
 Reads from a rotation field on the networked data pointed by ptr with the defined readAccuracy .
 
static void WriteRotation (Quaternion rotation, int *ptr, WriteAccuracy writeAccuracy)
 Writes to a rotation field on the networked data pointed by ptr with the defined writeAccuracy .
 
- Static Public Member Functions inherited from NetworkPosition
static Vector3 ReadPosition (int *ptr, ReadAccuracy readAccuracy)
 Reads from a position field on the networked data pointed by ptr with the defined readAccuracy .
 
static void WritePosition (Vector3 position, int *ptr, WriteAccuracy writeAccuracy)
 Writes to a position field on the networked data pointed by ptr with the defined writeAccuracy .
 
- Static Public Member Functions inherited from NetworkBehaviour
static NetworkBehaviourUtils.DictionaryInitializer< K, V > MakeInitializer< K, V > (Dictionary< K, V > dictionary)
 This is a special method that is meant to be used only for [Networked] properties inline initialization.
 
static NetworkBehaviourUtils.ArrayInitializer< T > MakeInitializer< T > (T[] array)
 This is a special method that is meant to be used only for [Networked] properties inline initialization.
 
static T * MakePtr< T > ()
 
static T * MakePtr< T > (T defaultValue)
 
static ref T MakeRef< T > ()
 
static ref T MakeRef< T > (T defaultValue)
 
static int NetworkDeserialize (NetworkRunner runner, byte *data, ref NetworkBehaviour result)
 
static int NetworkSerialize (NetworkRunner runner, NetworkBehaviour obj, byte *data)
 
static NetworkBehaviour NetworkUnwrap (NetworkRunner runner, NetworkBehaviourId wrapper)
 
static NetworkBehaviourId NetworkWrap (NetworkRunner runner, NetworkBehaviour obj)
 
static implicit operator NetworkBehaviourId (NetworkBehaviour behaviour)
 Converts NetworkBehaviour to NetworkBehaviourId.
 
- Static Public Member Functions inherited from Behaviour
static void DestroyBehaviour (Behaviour behaviour)
 Wrapper for Unity's GameObject.Destroy()
 

Public Attributes

InterpolatedErrorCorrectionSettings InterpolatedErrorCorrectionSettings
 A set of parameters to tune the interpolated correction of prediction error to be applied on the InterpolationTarget.
 
bool InterpolateErrorCorrection = true
 If the computed prediction error should be smoothly corrected on the InterpolationTarget according to the InterpolatedErrorCorrectionSettings.
 
Spaces InterpolationSpace = Spaces.World
 If the InterpolationTarget should be interpolated in world space or in the local space of a networked parent. Interpolating in local space requires more computations, but gives more accurate visuals if/when a parent rotates.
 
Transform InterpolationTarget
 The Transform object used for smooth view interpolation. Should be a non-physics GameObject, typically a child of this GameObject or a separate object without colliders.
 
float TargetInterpolationDelay = 0.030f
 In shared mode, how much behind (in seconds) the remote client's interpolated view will try to stay from the latest snapshot available. The smaller the value, the snappier the interpolation will be and the higher the changes of extrapolations and eventual error corrections (interpolated).
 
bool UseLegacySharedModeInterpolation = false
 If the legacy interpolation algorithm should be used in Shared Mode for this object.
 
- Public Attributes inherited from NetworkBehaviour
bool InvokeRpc
 
int ObjectIndex
 The index of this NetworkBehaviour, in the NetworkObject.NetworkedBehaviours array.
 
int offset
 Gives access to the offset (in 32 bit words) and count (in 32 bit words) of this behaviour backing data.
 
int * Ptr
 Pointer to the allocated memory associated with this Object.
 
- Public Attributes inherited from SimulationBehaviour
NetworkObject Object
 The NetworkObject this component is associated with. May be null if this GameObject does not have a NetworkObject.
 
NetworkRunner Runner
 The NetworkRunner this component is associated with.
 

Protected Member Functions

virtual void ApplyInterpolatedTransform (ref InterpolatedTransformParameters param)
 Applies the interpolated position and rotation values and prediction error corrections computed on Render to the InterpolationTarget.
 
virtual void GetUninterpolatedWorldPositions (ref InterpolationData data, out Vector3 posFrom, out Vector3 posTo)
 Retrieves the world position values from the From and To states made available in the interpolation data , setting them to posFrom and posTo , respectively.
 
virtual void GetUninterpolatedWorldRotations (ref InterpolationData data, out Quaternion rotFrom, out Quaternion rotTo)
 Retrieves the world rotation values from the From and To states made available in the interpolation data , setting them to rotFrom and rotTo , respectively.
 
- Protected Member Functions inherited from NetworkPositionRotation
override void CopyFromBufferToEngine ()
 Sets the values retrieved from the networked data to the respective engine (Unity) fields. If overriding this method in an inheritor, the base method should be called.
 
override void CopyFromEngineToBuffer ()
 Sets the values retrieved from the engine (Unity) to the respective networked fields. If overriding this method in an inheritor, the base method should be called.
 
virtual Quaternion GetEngineRotation ()
 Gets the rotation value from the engine. By default, the world rotation is set to be the output.
 
virtual void SetEngineRotation (Quaternion rot)
 Sets a rotation value to the engine. By default, the value is set to the transform's world rotation field.
 
- Protected Member Functions inherited from NetworkPosition
virtual void Awake ()
 Implements Unity's Awake event function. If overriding this method in an inheritor, the base method should be called.
 
virtual void CopyFromBufferToEngine ()
 Sets the position value retrieved from the networked data to the engine's position field. If overriding this method in an inheritor, the base method should be called.
 
virtual void CopyFromEngineToBuffer ()
 Sets the position value retrieved from the engine (Unity) to the respective networked field. If overriding this method in an inheritor, the base method should be called.
 
virtual Vector3 GetEnginePosition ()
 Gets the position value from the engine. By default, the world position is set to be the output.
 
virtual void OnEnable ()
 Implements Unity's OnEnable event function. If overriding this method in an inheritor, the base method should be called.
 
virtual void SetEnginePosition (Vector3 pos)
 Sets a position value to the engine. By default, the value is set to the transform's world position field.
 

Static Protected Attributes

const int WORD_COUNT_NT = OFFSET_ROT_STOPPED_CHANGING_TICK + WORD_COUNT_ROT_STOPPED_CHANGING_TICK
 Number of words used by a NetworkTransform instance on its networked data, including all inherited fields.
 
- Static Protected Attributes inherited from NetworkPositionRotation
const int WORD_COUNT_NPR = OFFSET_ROTATION + WORD_COUNT_ROTATION
 Number of words used by a NetworkPositionRotation instance on its networked data, including all inherited fields.
 
- Static Protected Attributes inherited from NetworkPosition
const int WORD_COUNT_NPOS = OFFSET_POSITION + WORD_COUNT_POSITION
 Number of words used by a NetworkPosition instance on its networked data, including all inherited fields.
 

Properties

override int BaseWordCount [get]
 
virtual Vector3 DefaultTeleportInterpolationAngularVelocity [get]
 The interpolation angular velocity used when calling TeleportToRotation and not specifying a value. By default, this value is Vector3.zero. Some behaviours like NetworkRigidbody and NetworkRigidbody2D override this property to provide better default values, like the latest known angular velocity of the rigid body.
 
virtual Vector3 DefaultTeleportInterpolationVelocity [get]
 The interpolation velocity used when calling TeleportToPosition and not specifying a value. By default, this value is Vector3.zero. Some behaviours like NetworkRigidbody and NetworkRigidbody2D override this property to provide better default values, like the latest known velocity of the rigid body.
 
- Properties inherited from NetworkPositionRotation
virtual int BaseWordCount [get]
 Number of words used by this class on the networked data buffer, including all inherited fields, to serve for reference to inheritors.
 
- Properties inherited from NetworkPosition
virtual int BaseWordCount [get]
 Number of words used by this class on the networked data buffer, including all inherited fields, to serve for reference to inheritors.
 
override int PositionWordOffset [get]
 Implements NetworkAreaOfInterestBehaviour by defining the word offset from the base pointer to the field that carries the position data used for Area of Interest management.
 
Transform Transform [get]
 Cached GameObject.transform reference.
 
- Properties inherited from NetworkAreaOfInterestBehaviour
abstract int PositionWordOffset [get]
 The int* offset for the Ptr, for the memory location of the position data.
 
- Properties inherited from NetworkBehaviour
virtual ? int DynamicWordCount [get]
 Override this value for custom memory allocations. This is for advanced use cases only, and cannot be used if NetworkedAttribute is used in the derived class.

 
NetworkBehaviourId Id [get]
 The unique identifier for this network behaviour.
 
InterpolationDataSources InterpolationDataSource [get, set]
 Get/Set the time frame this object is rendered in.
 
virtual bool InvokeOnChangedForInitialNonZeroValues [get]
 Override this property to change whether initial non-zero values assigned to [Networked] properties invoke OnChanged callbacks. For clients the initial value comes from the simulation snapshot, not from what has been set locally in the inspector.
 
int int count WordInfo [get]
 
- Properties inherited from SimulationBehaviour
bool CanReceiveCallback [get]
 
virtual bool HasInputAuthority [get]
 Returns true if the Simulation.LocalPlayer of the associated NetworkRunner is the designated as Input Authority for this network entity.
 
virtual bool HasStateAuthority [get]
 Returns true if the associated NetworkRunner is the State Authority for this network entity.
 
virtual bool IsProxy [get]
 Returns true if the associated NetworkRunner is neither the Input nor State Authority for this network entity. It is recommended to use !HasStateAuthority or !HasInputAuthority when possible instead, as this check requires evaluating both authorities - and is therefore less performant than the individual checks.
 

Additional Inherited Members

- Public Types inherited from NetworkBehaviour
enum  InterpolationDataSources
 Options for which time frame this object will render in. More...
 
- Protected Attributes inherited from NetworkPosition
NetworkPosition parentNP = null
 

Detailed Description

Replicates a Unity Transform's position and rotation states from the NetworkObject.StateAuthority to all other peers. Add this component to a GameObject to sync the position and rotation data. A NetworkObject is required on this GameObject or a parent of this GameObject.

Besides handling smooth interpolation of a target view transform, this behaviour also provides interpolated prediction error correction and special handling logic for teleports with controlled interpolation.

Member Function Documentation

◆ AfterAllTicks()

override void AfterAllTicks ( bool  resimulation,
int  tickCount 
)
virtual

Implements IAfterAllTicks. If overriding this method in an inheritor, the base method should be called. To extend the functionality of copying data from the engine to the networked buffer, override and extend CopyFromEngineToBuffer instead.

Reimplemented from NetworkPosition.

◆ AfterTick()

void AfterTick ( )

Implements IAfterTick. If overriding this method in an inheritor, the base method should be called.

Implements IAfterTick.

◆ BeforeUpdate()

override void BeforeUpdate ( )
virtual

Overrides NetworkPositionRotation.BeforeUpdate. If overriding this method in an inheritor, the base method should be called.

Reimplemented from NetworkPosition.

◆ CopyBackingFieldsToState()

override void CopyBackingFieldsToState ( bool  firstTime)
virtual

Implements NetworkBehaviour.CopyBackingFieldsToState. If overriding this method in an inheritor, the base method should be called.

Reimplemented from NetworkPosition.

◆ Despawned()

override void Despawned ( NetworkRunner  runner,
bool  hasState 
)
virtual

Called before the network object is despawned.

Parameters
hasStateIf the state of the behaviour is still accessible

Reimplemented from NetworkBehaviour.

◆ PredictedSpawnFailed()

virtual void PredictedSpawnFailed ( )
virtual

Implements IPredictedSpawnBehaviour.PredictedSpawnFailed and does nothing by default.

Implements IPredictedSpawnBehaviour.

◆ PredictedSpawnRender()

virtual void PredictedSpawnRender ( )
virtual

Implements IPredictedSpawnBehaviour.PredictedSpawnSpawned. If overriding this method in an inheritor, the base method should be called.

Implements IPredictedSpawnBehaviour.

◆ PredictedSpawnSpawned()

virtual void PredictedSpawnSpawned ( )
virtual

Implements IPredictedSpawnBehaviour.PredictedSpawnSpawned. If overriding this method in an inheritor, the base method should be called.

Implements IPredictedSpawnBehaviour.

◆ PredictedSpawnSuccess()

virtual void PredictedSpawnSuccess ( )
virtual

Implements IPredictedSpawnBehaviour.PredictedSpawnSuccess and does nothing by default.

Implements IPredictedSpawnBehaviour.

◆ PredictedSpawnUpdate()

virtual void PredictedSpawnUpdate ( )
virtual

Implements IPredictedSpawnBehaviour.PredictedSpawnUpdate and, by default, calls PredictedSpawnCacheTransformState. Behaviours that change the Transform state of this predict-spawned object should either be ordered before NetworkTransform or call PredictedSpawnCacheTransformState after doing so. If overriding this method in an inheritor, the base method should be called.

Implements IPredictedSpawnBehaviour.

◆ Render()

override void Render ( )
virtual

Overrides SimulationBehaviour.Render, computing the interpolated position and rotation values according to the NetworkBehaviour.InterpolationDataSource, updating the prediction error correction and calling ApplyInterpolatedTransform to apply the results to the InterpolationTarget.

Reimplemented from SimulationBehaviour.

◆ Spawned()

override void Spawned ( )
virtual

Overrides NetworkBehaviour.Spawned. If overriding this method in an inheritor, the base method should be called.

Reimplemented from NetworkPosition.

◆ TeleportToPosition()

void TeleportToPosition ( Vector3  position,
Vector3?  interpolationVel = null,
bool  interpolateBackwards = true 
)

Teleports the object to the provided position while making the networked state aware that the object was teleported and the view interpolation needs special handling. The position is immediately set to the transform's position field and additional data is stored in order to interpolate the view object between the ticks. While interpolating the visual representation of the networked object TO a tick where a teleport happened, the object's latest state (tick when the teleport is performed) will not be used, as doing so would cause the interpolation target to visually interpolate along the teleported distance. Instead, the view will be interpolated between the FROM state (tick before the teleport) and an artificial position computed based on this FROM state and an interpolation velocity (see interpolationVel ), in order to emulate how the object would behave if the teleport had not been performed.

Parameters
positionThe position which the object is being teleported to.
interpolationVelThe emulated velocity of the interpolation target while interpolating to a tick where a teleport happened. If null, the DefaultTeleportInterpolationVelocity will be used.
interpolateBackwardsIf the artificial position for teleport interpolation should be computed backwards (artificial From, based on the To state - the interpolation velocity) or forward (artificial To, based on the From state + interpolation velocity).

◆ TeleportToPositionRotation()

void TeleportToPositionRotation ( Vector3  position,
Quaternion  rotation,
Vector3?  interpolationVel = null,
Vector3?  interpolationAngularVel = null,
bool  interpolateBackwards = true 
)

Teleports the object to the provided position and rotation while making the networked state aware that the object was teleported and the view interpolation needs special handling. The rotation is immediately set to the transform's rotation field and additional data is stored in order to interpolate the view object between the ticks. See TeleportToPosition and TeleportToRotation for more details about why and how the special interpolation handling is performed.

Parameters
positionThe position which the object is being teleported to.
rotationThe rotation which the object is being teleported to.
interpolationVelThe emulated velocity of the interpolation target while interpolating to a tick where a teleport happened. If null, the DefaultTeleportInterpolationVelocity will be used.
interpolationAngularVelThe emulated angular velocity of the interpolation target while interpolating to a tick where a teleport happened. If null, the DefaultTeleportInterpolationAngularVelocity will be used.
interpolateBackwardsIf the artificial position for teleport interpolation should be computed backwards (artificial From, based on the To state - the interpolation velocity) or forward (artificial To, based on the From state + interpolation velocity).

◆ TeleportToRotation()

void TeleportToRotation ( Quaternion  rotation,
Vector3?  interpolationAngularVel = null,
bool  interpolateBackwards = true 
)

Teleports the object to the provided rotation while making the networked state aware that the object was teleported and the view interpolation needs special handling. The rotation is immediately set to the transform's rotation field and additional data is stored in order to interpolate the view object between the ticks. While interpolating the visual representation of the networked object TO a tick where a teleport happened, the object's latest state (tick when the teleport is performed) will not be used, as doing so would cause the interpolation target to visually interpolate along the teleported rotation. Instead, the view will be interpolated between the FROM state (tick before the teleport) and an artificial rotation computed based on this FROM state and an interpolation angular velocity (see interpolationAngularVel ), in order to emulate how the object would behave if the teleport had not been performed.

Parameters
rotationThe rotation which the object is being teleported to.
interpolationAngularVelThe emulated angular velocity of the interpolation target while interpolating to a tick where a teleport happened. If null, the DefaultTeleportInterpolationAngularVelocity will be used.
interpolateBackwardsIf the artificial position for teleport interpolation should be computed backwards (artificial From, based on the To state - the interpolation velocity) or forward (artificial To, based on the From state + interpolation velocity).