Remote Procedure Calls

Synchronizing an Actor’s properties, state and location is important for ensuring an accurate and natural multiplayer experience. However, actions taken by a player also need to be synchronized.

Polling values to see if they change to indicate a particular action is certainly possible, but most of the time it is preferable to Relay the action to other players so they can call a relevant function.

Remote Procedure Calls (RPCs) are messages sent between players that contain a function signature and optional arguments. These can call methods directly on Actors in other players’ worlds.

Strix facilitates this with a set of RPC related functions.

../_images/rpc9.png

Registering an RPC

Note

Registration of an RPC should take place on both the owner and replica Actor.

Functions in Actor Blueprints can be registered as an RPC function. When an RPC message is received that contains the function name of a registered function, that function is called.

The registration is completed by calling the Register Strix RPC function.

The Register Strix RPC function should be called on the On Sync Begin event provided by the Strix Replicator Component (See Replication). This ensures the internal network object and Type ID for this Actor have been correctly created.

The Register Strix RPC function takes the following arguments:

Target

Actor Object Reference

The Actor to register as the recipient of RPCs.
If an RPC with the registered function is received, this Actor will be the target of the function call.
Defaults to self.

Function Name

String

The UE name of the function to register, as seen in the My Blueprint panel under Functions.
Must be available on the Target object and be an exact string match.

Sending RPCs

RPCs can be sent from an Actor if the Actor has registered the function for that RPC. Sending RPCs requires a Target and a Function Name. The function name is the same as was registered (see above). The Target is the Actor whose owner and/or replicas will receive the RPC.

Send Rpc

Sends an RPC to a specific member. The member is a Strix Room Member struct and determines the specific client to send the RPC to. For how to obtain this information, see Getting Current Room Member Information.

Send Rpc to All

Sends an RPC to all members of the room, including this member.

Send Rpc to Object Owner

Sends an RPC to the Target Actor’s owner (see Ownership).

Send Rpc to Other Members

Sends an RPC to all members of the room, excluding this member.

Send Rpc to Room Owner

Sends an RPC to the current Room Owner (see Room Owner).

RPC Arguments

All Send RPC functions can take an array of Strix Relay Arg structs. These structs provide wrappers for arguments for input into the functions RPCs call.

Note

When sending an RPC, Strix does not check that the argument array is valid for the specific function signature. Be very careful regarding correct argument signatures, or else receiving the RPCs may fail.

The array for Args represents the list of arguments for a given function, in order. Even if the function only takes one argument, the argument must be inside an array.

To convert regular values into Strix Relay Args, drag out from the value and use the ToStrixRelayArg adapter for the values type. The resulting output of the conversion node is of the type Strix Relay Arg and can be dragged into the input of the RPC function (it will autogenerate the array conversion).

Strix supports a number of type conversions for basic Unreal types and containers. Type ToStrixRelayArg in the Blueprint Actions menu to see available types or check the list at Serializable RPC Arguments.

RPC Context

Strix contains a type called Strix Rpc Context. It contains the following members:

SenderMemberId

int

The member ID of the sender of the RPC

RoomId

int

The ID of the room this RPC was sent in

One may want to know some contextual information about an RPC, such as who sent it.

If a function signature contains a context argument like below:

func(…, FStrixRpcContext context, …)

Then Strix will automatically insert the RPC context into any RPC called with that function.

Note

The RPC context is not counted in the list of Strix Relay args to the function. For example, if the function signature is (int32, FStrixRpcContext, bool) then the Send RPC function should take int32, bool as its arguments. When called, Strix will pass the context to the function.