Photon Fusion 1.1.2

Public Member Functions | Properties | List of all members
RpcAttribute Class Reference

Flags a method as being a networked Remote Procedure Call. Only usable in a NetworkBehaviour. Calls to this method (from the indicated allowed RpcSources) will generate a network message, which will execute the method remotely on the indicated RpcTargets. The RPC method can include an empty RpcInfo argument, that will include meta information about the RPC on the receiving peer. More...

Inherits Attribute.

Public Member Functions

 RpcAttribute ()
 Constructor for RpcAttributes. More...
 
 RpcAttribute (RpcSources sources, RpcTargets targets)
 Constructor for RpcAttributes. More...
 

Properties

int Sources [get]
 The legal RpcSources types that can trigger this Rpc. Cast to int. Default value is (int)RpcSources.All. More...
 
int Targets [get]
 The RpcTargets types that will receive and invoke this method. Cast to int. Default value is (int)RpcTargets.All. More...
 
bool InvokeLocal = true [get, set]
 Indicates if the method should be called locally (on the RPC caller). This happens immediately. Default value is true. More...
 
bool InvokeResim [get, set]
 Indicates if this RPC will execute during resims, or only once on the first execution of the associated tick. Default value is false. More...
 
RpcChannel Channel = RpcChannel.Reliable [get, set]
 Specifies which RpcChannel to use. Default value is RpcChannel.Reliable More...
 
bool TickAligned = true [get, set]
 Indicates if this RPC's execution will be postponed until the local simulation catches up with the sender's Tick number. Even if set to false, the order of Rpcs is always preserved. Rpcs are deferred until all preceding Rpcs have executed. Default value is true. More...
 
RpcHostMode HostMode = RpcHostMode.SourceIsServer [get, set]
 Options for when the game is run in SimulationModes.Host mode and RPC is invoked by the host. More...
 

Detailed Description

Flags a method as being a networked Remote Procedure Call. Only usable in a NetworkBehaviour. Calls to this method (from the indicated allowed RpcSources) will generate a network message, which will execute the method remotely on the indicated RpcTargets. The RPC method can include an empty RpcInfo argument, that will include meta information about the RPC on the receiving peer.

Example:

| [Rpc(RpcSources.All, RpcTargets.All, InvokeLocal = false, InvokeResim = false, Channel = RpcChannel.Reliable, TickAligned = true)]
| public void RPC_Configure(NetworkObject no, string name, Color color, RpcInfo info = default) { }
To target a specific Player, use the RpcTargetAttribute: | [Rpc] | public void RpcFoo([RpcTarget] PlayerRef targetPlayer) {} Use RpcInvokeInfo as a return value to access meta information about the RPC send attempt, such as failure to send reasons, message size, etc.

Non-static RPCs are only valid on a NetworkBehaviour. Static RPCs can be implemented on SimulationBehaviours, and do not require a NetworkObject instance. Static RPC require the first argument to be NetworkRunner.

Static RPC Example: | [Rpc] | public static void RPC_Configure(NetworkRunner runner) { }

Constructor & Destructor Documentation

◆ RpcAttribute() [1/2]

Constructor for RpcAttributes.

◆ RpcAttribute() [2/2]

RpcAttribute ( RpcSources  sources,
RpcTargets  targets 
)

Constructor for RpcAttributes.

Parameters
sourcesThe legal RpcSources types that can trigger this Rpc. Default is RpcSources.All
targetsThe RpcTargets types that will receive and invoke this method. Default is RpcTargets.All

Property Documentation

◆ Channel

RpcChannel Channel = RpcChannel.Reliable
getset

Specifies which RpcChannel to use. Default value is RpcChannel.Reliable

◆ HostMode

Options for when the game is run in SimulationModes.Host mode and RPC is invoked by the host.

◆ InvokeLocal

bool InvokeLocal = true
getset

Indicates if the method should be called locally (on the RPC caller). This happens immediately. Default value is true.

◆ InvokeResim

bool InvokeResim
getset

Indicates if this RPC will execute during resims, or only once on the first execution of the associated tick. Default value is false.

◆ Sources

int Sources
get

The legal RpcSources types that can trigger this Rpc. Cast to int. Default value is (int)RpcSources.All.

◆ Targets

int Targets
get

The RpcTargets types that will receive and invoke this method. Cast to int. Default value is (int)RpcTargets.All.

◆ TickAligned

bool TickAligned = true
getset

Indicates if this RPC's execution will be postponed until the local simulation catches up with the sender's Tick number. Even if set to false, the order of Rpcs is always preserved. Rpcs are deferred until all preceding Rpcs have executed. Default value is true.