Photon Fusion 1.1.9

Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Properties | List of all members
NetworkBehaviour Class Reference

Base class for Fusion network components, which are associated with a NetworkObject. More...

Inherits SimulationBehaviour, ISpawned, and IDespawned.

Inherited by HitboxRoot, NetworkAreaOfInterestBehaviour, and NetworkMecanimAnimator.

Classes

struct  Interpolator
 Interpolator provides a set of methods to get the "from" and "to" ticks of the associated [Networked] property, as well as the current interpolation value for the two, but it also provides a Value property as a shortcut to get the actual interpolated value for those parameters.

See also
RawInterpolator
More...
 
struct  RawInterpolator
 RawInterpolator provides a set of methods to get the "from" and "to" ticks of the associated [Networked] property, as well as the current interpolation value for the two. All methods return raw memory pointers and expects the caller to be able to convert the data to the proper types.

See also
Interpolator<T>
More...
 

Public Types

enum  InterpolationDataSources
 Options for which time frame this object will render in. More...
 

Public Member Functions

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.
 
- Public Member Functions inherited from SimulationBehaviour
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 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

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.
 

Properties

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.
 

Detailed Description

Base class for Fusion network components, which are associated with a NetworkObject.

Derived from SimulationBehaviour, components derived from this class are associated with a NetworkRunner and Simulation. Components derived from this class are associated with a parent NetworkObject. and can use the NetworkedAttribute on properties to automate state synchronization, and can use the RpcAttribute on methods, to automate messaging.

Member Enumeration Documentation

◆ InterpolationDataSources

Options for which time frame this object will render in.

Enumerator
Auto 

Selects the most likely suitable time frame.

Snapshots 

Renders the object in the remote time frame, using the most recently consumed remote state tick.

Predicted 

Render the object in the local players time frame, interpolating between the most recent tick simulation result and the previous.

NoInterpolation 

Interpolation will not be calculated nor applied.

Member Function Documentation

◆ CopyBackingFieldsToState()

virtual void CopyBackingFieldsToState ( bool  firstTime)
virtual

◆ CopyStateFrom()

void CopyStateFrom ( NetworkBehaviour  source)

Copies entire state of passed in source NetworkBehaviour

Parameters
sourceSource NetworkBehaviour to copy data from

◆ Despawned()

virtual 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 in NetworkTransform, and HitboxRoot.

◆ FixedUpdateNetwork()

override void FixedUpdateNetwork ( )
virtual

Fusion FixedUpdate timing callback.

Reimplemented from SimulationBehaviour.

Reimplemented in NetworkMecanimAnimator.

◆ GetInput< T >() [1/2]

T? GetInput< T > ( )
Template Parameters
T
Type Constraints
T :unmanaged 
T :INetworkInput 

◆ GetInput< T >() [2/2]

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

The returned input struct originates from the NetworkObject.InputAuthority, and if valid contains the inputs supplied by that PlayerRef for the current simulation tick.

Type Constraints
T :unmanaged 
T :INetworkInput 

◆ GetInterpolationData() [1/2]

bool GetInterpolationData ( out InterpolationData  data,
bool?  predicted = null 
)

Get 'To' and 'From' states, and the Alpha (t) values needed for lerping.

Parameters
dataThe returned values.
predictedForce interpolation to the current Simulations time frame
Returns
True valid state data was returned.

◆ GetInterpolationData() [2/2]

bool GetInterpolationData ( out InterpolationData  data,
out bool  predicted 
)

Get 'To' and 'From' states, and the Alpha (t) values needed for interpolation.

Parameters
dataThe returned values.
predictedIf the interpolation data is in the predicted time frame (true) or between snapshots (false), according to the InterpolationDataSource.
Returns
True valid state data was returned.

◆ GetInterpolator()

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.

Parameters
propertyNameName of the [Networked] property
Returns
RawInterpolator for the networked property

◆ GetInterpolator< T >()

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.

Parameters
propertyNameName of the [Networked] property
Template Parameters
TType of the [Networked] property
Returns
Interpolator for the networked property
Type Constraints
T :struct 

◆ IsInterpolationDataPredicted()

virtual bool IsInterpolationDataPredicted ( )
virtual

If the behaviour data should be interpolated between latest predicted states or between snapshots.

Returns

Reimplemented in NetworkRigidbodyBase.

◆ MakePtr< T >() [1/2]

static T * MakePtr< T > ( )
static
Type Constraints
T :unmanaged 

◆ MakePtr< T >() [2/2]

static T * MakePtr< T > ( defaultValue)
static
Type Constraints
T :unmanaged 

◆ MakeRef< T >() [1/2]

static ref T MakeRef< T > ( )
static
Type Constraints
T :unmanaged 

◆ MakeRef< T >() [2/2]

static ref T MakeRef< T > ( defaultValue)
static
Type Constraints
T :unmanaged 

◆ OnChangeAdd< T >() [1/2]

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.

Parameters
wordOffsetWord offset to monitor for changes
wordCountHow many words to monitor for changes, from offset and up
callbackCallback to invoke
Template Parameters
TType of the behaviour
Returns
Reference struct that can be used to remove this callback later
Type Constraints
T :NetworkBehaviour 

◆ OnChangeAdd< T >() [2/2]

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.

Parameters
propertyNameName of the property to monitor for changes
callbackCallback to invoke
Template Parameters
TType of the behaviour
Returns
Reference struct that can be used to remove this callback later
Type Constraints
T :NetworkBehaviour 

◆ OnChangeRemove()

bool OnChangeRemove ( NetworkBehaviourCallbackReference  reference)

Removes a specific OnChange callback from this behaviour.

Parameters
referenceThe reference returned by OnChangeAdd
Returns
Removal succeeded

◆ operator NetworkBehaviourId()

static implicit operator NetworkBehaviourId ( NetworkBehaviour  behaviour)
static

Converts NetworkBehaviour to NetworkBehaviourId.

Parameters
behaviour
Returns

◆ Spawned()

virtual void Spawned ( )
virtual

Property Documentation

◆ InvokeOnChangedForInitialNonZeroValues

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.

Returns "true" by default.