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.
Inherited Members
Namespace: Unity.Netcode.Components
Assembly: Unity.Netcode.Runtime.dll
Syntax
[DisallowMultipleComponent]
[AddComponentMenu("Netcode/Network Transform")]
public class NetworkTransform : NetworkBehaviour
Fields
AuthorityMode
Determines whether this Network
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 |
---|---|
Network |
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 Buffered
- The Network
Transform 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 Client
Server .
Declaration
public bool AutoOwnerAuthorityTickOffset
Field Value
Type | Description |
---|---|
bool |
Remarks
When calculating the total tick latency as time value, the Tick
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 Network
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.
Tick
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 |
---|---|
Network |
PositionInterpolationType
The position interpolation type to use for the Network
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 |
---|---|
Network |
Remarks
- Legacy
Lerp Yields the original Netcode for GameObjects lerp result. - LerpUses the newer linear buffer queue consumption approach that maintains a consistent time to the next target.
- Smooth
Dampening Uses the newer linear buffer queue consumption approach and adjusts based on the rate of change.
- You can have mixed interpolation types between position, rotation, and scale on the same Network
Transform instance. - You can change the interpolation type during runtime, but changing between Network
Transform. can result in a slight stutter if the object is in motion.Interpolation Types
PositionLerpSmoothing
Controls position interpolation smoothing.
Declaration
public bool PositionLerpSmoothing
Field Value
Type | Description |
---|---|
bool |
Remarks
When enabled, the Buffered
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 Network
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 |
---|---|
Network |
Remarks
- Legacy
Lerp Yields the original Netcode for GameObjects lerp result. - LerpUses the newer linear buffer queue consumption approach that maintains a consistent time to the next target.
- Smooth
Dampening Uses the newer linear buffer queue consumption approach and adjusts based on the rate of change.
- You can have mixed interpolation types between position, rotation, and scale on the same Network
Transform instance. - You can change the interpolation type during runtime, but changing between Network
Transform. can result in a slight stutter if the object is in motion.Interpolation Types
RotationLerpSmoothing
Controls rotation interpolation smoothing.
Declaration
public bool RotationLerpSmoothing
Field Value
Type | Description |
---|---|
bool |
Remarks
When enabled, the Buffered
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 Network
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 |
---|---|
Network |
Remarks
- Legacy
Lerp Yields the original Netcode for GameObjects lerp result. - LerpUses the newer linear buffer queue consumption approach that maintains a consistent time to the next target.
- Smooth
Dampening Uses the newer linear buffer queue consumption approach and adjusts based on the rate of change.
- You can have mixed interpolation types between position, rotation, and scale on the same Network
Transform instance. - You can change the interpolation type during runtime, but changing between Network
Transform. can result in a slight stutter if the object is in motion.Interpolation Types
ScaleLerpSmoothing
Controls scale interpolation smoothing.
Declaration
public bool ScaleLerpSmoothing
Field Value
Type | Description |
---|---|
bool |
Remarks
When enabled, the Buffered
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 Network
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 Network
Declaration
public bool SwitchTransformSpaceWhenParented
Field Value
Type | Description |
---|---|
bool |
Remarks
Only works with Network
Tick
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 Use
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 Use
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 Use
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 Network
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. Use
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.
m_AddLogEntry
Declaration
protected NetworkTransform.AddLogEntryHandler m_AddLogEntry
Field Value
Type | Description |
---|---|
Network |
m_CachedNetworkManager
Internally used by Network
Declaration
protected NetworkManager m_CachedNetworkManager
Field Value
Type | Description |
---|---|
Network |
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 |
---|---|
Network |
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). |
Returns
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). |
Returns
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). |
Returns
Type | Description |
---|---|
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 |
---|---|---|
Network |
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
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
IsServerAuthoritative()
Method to determine if this Network
Declaration
public bool IsServerAuthoritative()
Returns
Type | Description |
---|---|
bool | true or false |
Remarks
When using a Distributed
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 |
---|---|---|
Network |
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 Game
Declaration
public override void OnDestroy()
Overrides
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 Network
Declaration
public override void OnGainedOwnership()
Overrides
OnInitialize(ref NetworkTransformState)
Invoked when first spawned and when ownership changes.
Declaration
protected virtual void OnInitialize(ref NetworkTransform.NetworkTransformState replicatedState)
Parameters
Type | Name | Description |
---|---|---|
Network |
replicatedState | the current Network |
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 |
---|---|---|
Network |
replicatedState | The NetworkVariable containing the Network |
OnIsServerAuthoritative()
Determines whether the Network
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 Network
Declaration
public override void OnLostOwnership()
Overrides
OnNetworkDespawn()
Gets called when the Network
Declaration
public override void OnNetworkDespawn()
Overrides
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 |
---|---|---|
Network |
parentNetworkObject | the new Network |
Overrides
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 Sync
Owner Transform When Parented - Enabling Allow
Owner To Parent - Enabling Switch
Transform Space When Parented
-- 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 Network
Object parent) - Local space back to world space (Network
Object parent to root-null parent) - Local space to local space (Network
Object 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 Network
Declaration
public override void OnNetworkSpawn()
Overrides
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 |
---|---|---|
Network |
oldState | the previous Network |
Network |
newState |
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
Overrides
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
Network
Declaration
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer) where T : IReaderWriter
Parameters
Type | Name | Description |
---|---|---|
Buffer |
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
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 Network
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:
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 Network |
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 On
Exceptions
Type | Condition |
---|---|
Exception | Thrown when called from a non-authoritative context (client without ownership) |