Photon Fusion 2.1.1

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

Public Member Functions

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

Static Public Attributes

const int MaxPayloadSize = 512
 Maximum allowed size for the payload of the RPC message.

Properties

RpcChannel Channel = RpcChannel.Reliable [get, set]
 Specifies which RpcChannel to use. Default value is RpcChannel.Reliable.
RpcHostMode HostMode = RpcHostMode.SourceIsServer [get, set]
 Options for when the game is run in SimulationModes.Host mode and RPC is invoked by the host.
bool InvokeLocal [get, set]
 Indicates if the method should be called locally (on the RPC caller). This happens immediately. Default value is true. Consider using InvokeLocalMode for more options.
RpcInvokeLocalMode InvokeLocalMode = RpcInvokeLocalMode.Immediate [get, set]
 Indicates if the method should be called locally (on the RPC caller). This happens immediately. Default value is RpcInvokeLocalMode.Immediate.
uint Key = 0 [get, set]
 Assign a unique 24-bit key to this RPC if this RPC causes auto-key conflicts.
RpcSources Sources = RpcSources.All [get]
 The legal RpcSources types that can trigger this Rpc. Cast to int. Default value is (int)RpcSources.All.
RpcTargets Targets = RpcTargets.All [get]
 The RpcTargets types that will receive and invoke this method. Cast to int. Default value is (int)RpcTargets.All.
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.

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, Channel = RpcChannel.Reliable, TickAligned = true)]<br></br>
| public void RPC_Configure(NetworkObject no, string name, Color color, RpcInfo info = default) { }
The primary Fusion component for networked GameObject entities. This stores the object's network iden...
Definition NetworkObject.cs:39
bool InvokeLocal
Indicates if the method should be called locally (on the RPC caller). This happens immediately....
Definition RpcAttribute.cs:51
RpcChannel Channel
Specifies which RpcChannel to use. Default value is RpcChannel.Reliable.
Definition RpcAttribute.cs:66
bool TickAligned
Indicates if this RPC's execution will be postponed until the local simulation catches up with the se...
Definition RpcAttribute.cs:74
RpcChannel
Flags for the RPC channel.
Definition RpcChannel.cs:6
RpcTargets
Enum representing the targets of an RPC message.
Definition RpcTargets.cs:8
RpcSources
Enum representing the sources of an RPC message.
Definition RpcSources.cs:8
RpcInfo is a struct that contains information about the RPC message.
Definition RpcInfo.cs:9

To target a specific Player, use the RpcTargetAttribute:

| [Rpc]
| public void RpcFoo([RpcTarget] PlayerRef targetPlayer) {}
Represents a Fusion player.
Definition PlayerRef.cs:20

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) { }
Represents a Server or Client Simulation. IMPORTANT: You can only use a NetworkRunner once....
Definition NetworkRunner.HostMigration.API.cs:8

Constructor & Destructor Documentation

◆ RpcAttribute()

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