Photon Fusion
2.1.1
Add to any NetworkObject Transform, or its associated child Transforms to automatically synchronize TRSP (Position/Rotation/Scale/Parent). More...
Inherits NetworkTRSP, INetworkTRSPTeleport, IBeforeAllTicks, IAfterAllTicks, IBeforeCopyPreviousState, and IAfterClientPredictionReset.
Public Types | |
| enum | NetworkTransformFlags |
| Flags used to configure NetworkTransform behaviour. More... | |
Public Member Functions | |
| delegate void | ApplyCorrectionDelegate (NetworkTransform networkTransform, float physicsDt, float physicsFps, AbstractPhysicsBody physicsBody, float timeSinceLastOnCollisionEnter, ref KinematicSnapshot localSnapshot, ref KinematicSnapshot remoteSnapshot, ref KinematicSnapshot extrapolatedSnapshot) |
| Define a custom implementation to override the default forecast heuristics, when applying a correction to the local physics body. | |
| delegate float | CustomErrorDetectionDelegate (NetworkTransform networkTransform, float physicsDt, AbstractPhysicsBody physicsBody, Vector3 previousLocalPosition, Vector3 previousExtrapolatedPosition, ref KinematicSnapshot localSnapshot, ref KinematicSnapshot extrapolatedSnapshot) |
| Define a custom implementation to override the default error detection heuristics. | |
| delegate void | CustomForecastDelegate (NetworkTransform networkTransform, float physicsDt, AbstractPhysicsBody physicsBody, float ticksToExtrapolate, ref KinematicSnapshot localSnapshot, ref KinematicSnapshot remoteSnapshot, out KinematicSnapshot extrapolatedSnapshot) |
| NetworkTransform - The NetworkTransform instance. | |
| bool | IsTraceEnabled () |
| override 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. | |
| override void | SetAreaOfInterestOverride (NetworkObject obj) |
| Manually set the NetworkObject used as the AreaOfInterestOverride. | |
| void | SetTraceEnabled (bool enabled) |
| Enables collection of trace information from the NetworkTransform system. | |
| override void | Spawned () |
| Post spawn callback. | |
| void | Teleport (Vector3? position=null, Quaternion? rotation=null) |
| Teleport the object to a new position. Network the Teleport event and disable interpolation so the object snaps to the new position. | |
| Public Member Functions inherited from NetworkBehaviour | |
| virtual void | CopyBackingFieldsToState (bool firstTime) |
| Copies the backing fields to the state. This method is meant to be overridden in derived classes. | |
| void | CopyStateFrom (NetworkBehaviour source) |
| Copies entire state of passed in source NetworkBehaviour. | |
| virtual void | CopyStateToBackingFields () |
| Copies the state to the backing fields. This method is meant to be overridden in derived classes. | |
| virtual void | Despawned (NetworkRunner runner, bool hasState) |
| Called before the network object is despawned. | |
| override void | FixedUpdateNetwork () |
| Fixed update callback for networked behaviours. | |
| ArrayReader< T > | GetArrayReader< T > (string property) |
| Gets an ArrayReader for a network array of type T. | |
| BehaviourReader< T > | GetBehaviourReader< T > (string property) |
| Gets a BehaviourReader for a network behaviour of type T. | |
| ChangeDetector | GetChangeDetector (ChangeDetector.Source source, bool copyInitial=true) |
| Creates a ChangeDetector for this network behaviour. | |
| DictionaryReader< K, V > | GetDictionaryReader< K, V > (string property) |
| Gets a DictionaryReader for a network dictionary with keys of type K and values of type V. | |
| 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). | |
| LinkListReader< T > | GetLinkListReader< T > (string property) |
| Gets a LinkListReader for a network linked list of type T. | |
| int | GetLocalAuthorityMask () |
| Gets a bitmask of AuthorityMasks flags, representing the current local authority over this NetworkObject. | |
| PropertyReader< T > | GetPropertyReader< T > (string property) |
| Gets a PropertyReader for a property of type T in this network behaviour. | |
| ref T | ReinterpretState< T > (int offset=0) |
| Allows read and write access to the internal state buffer. | |
| void | ReplicateTo (PlayerRef player, bool replicate) |
| Controls if this network behaviours state is replicated to a player or not. | |
| void | ReplicateToAll (bool replicate) |
| Sets the default replicated state for this behaviour, this by default is true so calling ReplicateToAll(true) does nothing if ReplicateToAll(false) hasn't been called before. | |
| void | ResetState () |
| Resets the state of the object to the original state. | |
| bool | TryGetSnapshotsBuffers (out NetworkBehaviourBuffer from, out NetworkBehaviourBuffer to, out float alpha) |
| Tries to get the snapshot buffers for this network behaviour. | |
| Public Member Functions inherited from Behaviour | |
| T | AddBehaviour< T > () |
| Wrapper for Unity's GameObject.AddComponent(). | |
| T | GetBehaviour< T > () |
| Wrapper for Unity's GameObject.GetComponentInChildren(). | |
| bool | TryGetBehaviour< T > (out T behaviour) |
| Wrapper for Unity's GameObject.TryGetComponent(). | |
| Public Member Functions inherited from IElementReaderWriter< T > | |
| int | GetElementHashCode (T element) |
| Calculate the hash code of an element. | |
| void | Write (byte *data, int index, T element) |
| Writes an element to the specified index in the byte array. | |
| Public Member Functions inherited from IAfterClientPredictionReset | |
| void | AfterClientPredictionReset () |
| Called at the very start of the resimulation loop (on clients with prediction enabled), immediately after state is set to the latest server snapshot. | |
Public Attributes | |
| NetworkTransformFlags | ConfigFlags = NetworkTransformFlags.None |
| Flags to configure the NetworkTransform. | |
| NetworkTransformTrace | CurrentTrace = null |
| Read the current trace data, must first be enabled via SetTraceEnabled(bool), which is compiled out in non DEBUG builds. | |
| ApplyCorrectionDelegate | CustomApplyCorrection |
| Define a custom implementation to override the default forecast heuristics, when moving the local physics body towards the extrapolated remote position. | |
| CustomErrorDetectionDelegate | CustomErrorDetection |
| Provide a custom forecast error detection heuristic to override the default behaviour. | |
| CustomForecastDelegate | CustomForecast |
| Define a custom implementation to override the default forecast heuristics. | |
| PhysicsSettings | PhysicsSettings = new() |
| Physics settings. | |
| bool | SyncParent = false |
| Enables synchronization of transform.parent. NOTE: Parent GameObjects must have a NetworkBehaviour derived component to be a valid parent, parent must belong to a different NetworkObject than this Object. | |
| bool | SyncScale = false |
| Enables synchronization of LocalScale. | |
| Public Attributes inherited from NetworkBehaviour | |
| int | offset |
| Gives access to the offset (in 32 bit words) and count (in 32 bit words) of this behaviour backing data. | |
| int * | Ptr |
| Internal Fusion plumbing. Do not use directly. | |
Properties | |
| bool | AutoUpdateAreaOfInterestOverride [get, set] |
| Determines if parent changes should automatically call SetAreaOfInterestOverride(NetworkObject), and assign the parent NetworkObject as the override. Default is true, as you typically will want player interest in this object to reflect player interest in the nested parent object. For example, if a player is carrying an nested Object, players should only see that carried Object if they see the player. Additionally, AOI works in world space, and NetworkTransform operates in local space, so any AOI position values of nested Objects will ALWAYS be invalid, so nested Objects should always have their AOI Override set to a non-nested Object. | |
| bool | HasForecastEnabled [get] |
| True if forecast physics is enabled globally and locally on the object. Only used to know if physics is enabled on the NetworkTransform, to know if it has a physics body use NetworkTransform.HasPhysicsBody. | |
| NetworkPhysicsData | PhysicsData [get] |
| The networked physics data. | |
| Properties inherited from NetworkTRSP | |
| NetworkTRSPData | Data [get] |
| The networked data of this NetworkTRSP. | |
| bool | IsMainTRSP [get] |
| The main NetworkTRSP is at the root of the NetworkObject and it will be used for area of interest operations and parenting of the NetworkObject. | |
| ref NetworkTRSPData | State [get] |
| A reference to the networked data of this NetworkTRSP. | |
| Properties inherited from NetworkBehaviour | |
| Tick | ChangedTick [get] |
| The tick the data on this networked behaviour changed. | |
| 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. | |
| bool | HasInputAuthority [get] |
| Returns true if the Simulation.LocalPlayer of the associated NetworkRunner is the designated as Input Source for this network entity. | |
| bool | HasStateAuthority [get] |
| Returns true if the associated NetworkRunner is the State Source for this network entity. | |
| NetworkBehaviourId | Id [get] |
| The unique identifier for this network behaviour. | |
| 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. | |
| NetworkBehaviourBuffer | StateBuffer [get] |
| Gets the state buffer associated with the network behaviour. | |
| bool | StateBufferIsValid [get] |
| Gets a value indicating whether the state buffer is valid. | |
| Properties inherited from SimulationBehaviour | |
| bool | CanReceiveRenderCallback [get] |
| Gets a value indicating whether this instance can receive render callbacks. | |
| bool | CanReceiveSimulationCallback [get] |
| Gets a value indicating whether this instance can receive simulation callbacks. | |
| bool | IsValid [get] |
| NetworkObject | Object [get] |
| The NetworkObject this component is associated with. Not applicable to SimulationBehaviours as they cannot be associated with a NetworkObject. | |
| NetworkRunner | Runner [get] |
| The NetworkRunner this component is associated with. | |
Additional Inherited Members | |
| Static Public Member Functions inherited from NetworkBehaviour | |
| static ArrayReader< T > | GetArrayReader< T > (Type behaviourType, string property, IElementReaderWriter< T > readerWriter=null) |
| Gets an ArrayReader for a network array of type T in a network behaviour of a specific type. | |
| static BehaviourReader< T > | GetBehaviourReader< T > (NetworkRunner runner, Type behaviourType, string property) |
| Gets a BehaviourReader for a network behaviour of type T. | |
| static BehaviourReader< TProperty > | GetBehaviourReader< TBehaviour, TProperty > (NetworkRunner runner, string property) |
| Gets a BehaviourReader for a network behaviour with a specific property of type TProperty. | |
| static DictionaryReader< K, V > | GetDictionaryReader< K, V > (Type behaviourType, string property, IElementReaderWriter< K > keyReaderWriter=null, IElementReaderWriter< V > valueReaderWriter=null) |
| Gets a DictionaryReader for a network dictionary with keys of type K and values of type V in a network behaviour of a specific type. | |
| static LinkListReader< T > | GetLinkListReader< T > (Type behaviourType, string property, IElementReaderWriter< T > readerWriter=null) |
| Gets a LinkListReader for a network linked list of type T in a network behaviour of a specific type. | |
| static PropertyReader< T > | GetPropertyReader< T > (Type behaviourType, string property) |
| Gets a PropertyReader for a property of type T in a network behaviour of a specific type. | |
| static PropertyReader< TProperty > | GetPropertyReader< TBehaviour, TProperty > (string property) |
| Gets a PropertyReader for a property of type TProperty in a network behaviour of type TBehaviour. | |
| 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 > () |
| Creates a pointer to a value of type T. This method is meant to be used only for [Networked] properties inline initialization. | |
| static T * | MakePtr< T > (T defaultValue) |
| Creates a pointer to a value of type T, initializing it with the provided default value. This method is meant to be used only for [Networked] properties inline initialization. | |
| static ref T | MakeRef< T > () |
| Creates a reference to a value of type T. This method is meant to be used only for [Networked] properties inline initialization. | |
| static ref T | MakeRef< T > (T defaultValue) |
| Creates a reference to a value of type T, initializing it with the provided default value. This method is meant to be used only for [Networked] properties inline initialization. | |
| static int | NetworkDeserialize (NetworkRunner runner, byte *data, ref NetworkBehaviour result) |
| Deserializes a NetworkBehaviour from a byte array. | |
| static int | NetworkSerialize (NetworkRunner runner, NetworkBehaviour obj, byte *data) |
| Serializes a NetworkBehaviour into a byte array. | |
| static NetworkBehaviour | NetworkUnwrap (NetworkRunner runner, NetworkBehaviourId wrapper) |
| Converts a NetworkBehaviourId to a NetworkBehaviour. | |
| static NetworkBehaviourId | NetworkWrap (NetworkBehaviour obj) |
| Converts a NetworkBehaviour to a NetworkBehaviourId. | |
| static NetworkBehaviourId | NetworkWrap (NetworkRunner runner, NetworkBehaviour obj) |
| Converts a NetworkBehaviour to a NetworkBehaviourId. | |
| 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(). | |
| Protected Member Functions inherited from NetworkBehaviour | |
| virtual bool | ReplicateTo (PlayerRef player) |
| Determines whether to replicate the network behaviour to the specified player. This method can be overridden in derived classes to implement custom replication logic. | |
| Static Protected Member Functions inherited from NetworkTRSP | |
| static void | Render (NetworkTRSP behaviour, Transform transform, bool syncScale, bool syncParent, bool local, ref Tick initial) |
| Default Render handling for NetworkTRSP derived classes. | |
| static void | ResolveAOIOverride (NetworkTRSP behaviour, Transform parent) |
| Recursively attempts to find nested parent NetworkObject, and if found assigns that NetworkObject as the AreaOfInterestOverride. | |
| static void | SetParentTransform (NetworkTRSP behaviour, Transform transform, NetworkBehaviourId parentId) |
| Default handling for setting a NetworkTRSP's parent using a NetworkBehaviourId value. | |
| static void | Teleport (NetworkTRSP behaviour, Transform transform, Vector3? position=null, Quaternion? rotation=null) |
| The default Teleport implementation for NetworkTRSP derived classes. | |
| Protected Attributes inherited from NetworkTRSP | |
| Tick | reenabledTick |
| The tick on which this NetworkTRSP was last re-enabled (right after Spawned doesn't count). | |
Add to any NetworkObject Transform, or its associated child Transforms to automatically synchronize TRSP (Position/Rotation/Scale/Parent).
Flags used to configure NetworkTransform behaviour.
| Enumerator | |
|---|---|
| None | No flags. |
| DisableSharedModeInterpolation | Disable interpolation on State Authority in Shared Mode. You should disable interpolation if your controller code moves an object inside of Update() rather than FixedUpdateNetwork(). |
| delegate void ApplyCorrectionDelegate | ( | NetworkTransform | networkTransform, |
| float | physicsDt, | ||
| float | physicsFps, | ||
| AbstractPhysicsBody | physicsBody, | ||
| float | timeSinceLastOnCollisionEnter, | ||
| ref KinematicSnapshot | localSnapshot, | ||
| ref KinematicSnapshot | remoteSnapshot, | ||
| ref KinematicSnapshot | extrapolatedSnapshot ) |
Define a custom implementation to override the default forecast heuristics, when applying a correction to the local physics body.
| networkTransform | The network transform we are appplying a correction to |
| physicsDt | The rate physics in running at in seconds |
| physicsFps | 1 / physicsDt or the number of physics frames per second |
| physicsBody | The physics body |
| timeSinceLastOnCollisionEnter | How long since a collision last started? |
| localSnapshot | State of the local physics body |
| remoteSnapshot | State of the remote physics body |
| extrapolatedSnapshot | State of the extrapolation |
| delegate float CustomErrorDetectionDelegate | ( | NetworkTransform | networkTransform, |
| float | physicsDt, | ||
| AbstractPhysicsBody | physicsBody, | ||
| Vector3 | previousLocalPosition, | ||
| Vector3 | previousExtrapolatedPosition, | ||
| ref KinematicSnapshot | localSnapshot, | ||
| ref KinematicSnapshot | extrapolatedSnapshot ) |
Define a custom implementation to override the default error detection heuristics.
| networkTransform | The network transform we are evaluating |
| physicsDt | The rate physics is running at in seconds |
| physicsBody | The physics body |
| previousLocalPosition | Local position from the previous physics tick |
| previousExtrapolatedPosition | Extrapolated position from the previous physics tick |
| localSnapshot | Current state of the local physics body |
| extrapolatedSnapshot | Current extrapolated state |
Score: Positive = error detected, Negative = healthy correction, Zero = neutral.
Score*physicsDt will accumalated each frame until it crosses the PhysicsSettings.MaxErrorTotalTime at which point an immediate move will be triggered
| delegate void CustomForecastDelegate | ( | NetworkTransform | networkTransform, |
| float | physicsDt, | ||
| AbstractPhysicsBody | physicsBody, | ||
| float | ticksToExtrapolate, | ||
| ref KinematicSnapshot | localSnapshot, | ||
| ref KinematicSnapshot | remoteSnapshot, | ||
| out KinematicSnapshot | extrapolatedSnapshot ) |
NetworkTransform - The NetworkTransform instance.
AbstractPhysicsBody - Abstraction to work with the rigidbody attached.
First KinematicSnapshot - Remote kinematic data, represent the latest kinematic/physics data confirmed from the authority.
Second KinematicSnapshot - Local kinematic data, represent the local kinematic/physics data of the physics body.
Float - Time since the last forecast iteration, normally equals to Time.FixedDeltaTime.
Define a custom implementation to override the default forecast heuristics, when extrapolating the remote position.
| networkTransform | The network transform we are appplying a correction to |
| physicsDt | The rate physics in running at in seconds |
| physicsBody | The physics body |
| ticksToExtrapolate | How many ticks forward to extrapolate. The time to extrapolate forward should be calculated by ticksToExtrapolate * networkTransform.Runner.DeltaTime. Note this is clamped by PhysicsSettings.MaxExtrapolationTime, in ticks |
| localSnapshot | State of the local physics body |
| remoteSnapshot | State of the remote physics body |
| extrapolatedSnapshot | This delegate should create the extrapolation here |
| bool IsTraceEnabled | ( | ) |
|
virtual |
Manually set the NetworkObject used as the AreaOfInterestOverride.
| obj | NetworkObject to use as the AreaOfInterestOverride. |
Reimplemented from NetworkTRSP.
| void SetTraceEnabled | ( | bool | enabled | ) |
Enables collection of trace information from the NetworkTransform system.
Data is only collected if DEBUG dll's are being used
| enabled |
| void Teleport | ( | Vector3? | position = null, |
| Quaternion? | rotation = null ) |
Teleport the object to a new position. Network the Teleport event and disable interpolation so the object snaps to the new position.
When HasPhysicsBody and HasForecastEnabled are true the RigidBody.position is adjusted in addition to Transform.position. Otherwise just the Transform.position is changed suspending interpolation between the previous tick state and the current tick state in Render(), on this peer and all remote peers.
Implements INetworkTRSPTeleport.
| CustomErrorDetectionDelegate CustomErrorDetection |
Provide a custom forecast error detection heuristic to override the default behaviour.
This heuristic is used to detect stalls in the forecasting logic and can be used to trigger a hard reset of the forecast system.
When null, the default heuristic is used which detects persistent error states where the error direction is consistent but correction progress is insufficient.