Network RPC System
The RPC (Remote Procedure Call) system allows you to invoke functions on remote machines. It uses Plasma's reflection system for automatic parameter serialization and supports multiple targeting modes and reliability options.
Overview
RPCs are the primary way to trigger actions across the network -- firing a weapon, applying damage, changing game state, or broadcasting events. The system provides:
Reflection-based invocation-- Functions are invoked through RTTI, with manual registration for target and reliability.
Type-safe parameters-- Arguments are serialized via
plVariantwith type checking.Multiple targets-- Server-only, owner-only, all clients, or specific clients.
Configurable reliability-- Reliable ordered, reliable, unreliable ordered, or unreliable.
Accessing the RPC Manager
RPC Targets
Target | Description |
|---|---|
| Execute on the server only |
| Execute on the owning client only |
| Execute on all clients (not the server) |
| Execute on all machines |
| Execute on a specific list of clients |
RPC Reliability
Reliability | Description |
|---|---|
| May be lost |
| May be lost, but in order |
| Always delivered, may be out of order |
| Always delivered, always in order (default) |
Defining an RPC
An RPC function must be declared as a reflected function property (PL_FUNCTION_PROPERTY) so the RPC manager can discover and invoke it through RTTI. The RPC target and reliability are then registered manually at runtime.
Step 1: Declare the Function
Step 2: Reflect as a Function Property
In the reflection block, expose the function via PL_FUNCTION_PROPERTY. Do not attach plNetworkRpcAttribute here -- see the warning below.
Step 3: Register the RPC at Runtime
Register the RPC in OnSimulationStarted() using RegisterRpc():
Calling an RPC
Using Macros (Simplest)
Using the Manager Directly
Macro Reference
Macro | Description |
|---|---|
| Call RPC from a |
| Call RPC from any component with |
| Alias for |
| Alias for |
| Alias for |
| Alias for |
| Declare an RPC function signature in a header |
Supported Parameter Types
RPCs support any type that can be stored in plVariant:
bool,plInt32,plUInt32,plInt64,plUInt64float,doubleplStringplVec2,plVec3,plVec4plQuatplColor
RPC Execution Flow
The caller invokes
CallRpc()(or uses a macro).The RPC manager serializes the function name hash, component net ID, and arguments into a network message.
The message is sent to the appropriate target(s) based on the RPC's target configuration.
On the receiving machine,
HandleRpcMessage()deserializes the message, finds the target component and function, and invokes it via reflection.