Getting Started
Package Types
Scene Setup
Economy
Scripting
Components
Guidelines
Support
Network Events (RPC)
Overview
In netcode speak an RPC or “Remote Procedure Call” is a means of triggering an Event with Data on other clients connected to the server.
Think of an RPC like a text message. You can send a packet of data directly to a single friend, or send it in a group chat and everyone will receive the message.
RPC’s are useful for “one-shot” events like VFX or custom netcode where synced objects don’t make sense.
Breakdown
When you send
an RPC it travels to the server, then to all receivers
. In the image above SendTo
is set to Others
. This means the Receive Event
will be called on all other clients.
Imagine an invisible thread between the SendEvent
and ReceiveEvent
nodes.
ID
Events are parsed on local clients based on the ID
. The ID
is type byte
which allows for values between 0-255
. It’s important to always use unique bytes for your events or else clients will begin incorrectly interpreting events.
It’s recommended to abstract your event ID’s to named variables somewhere in your project.
Arguments
Along with the event you can send up to 5 arguments
. This should be a minimal amount of data that is required for the event. For example, for an event that plays an explosion VFX you might want to send a Vector3
for the position of the explosion.
Remember its critical to keep network packets small. Only include the data you need.
Supported Types
bool
byte
short
int
long
float
double
string
Vector2
Vector3
Vector4
Quaternion
Color
Color32
DateTime
+ Array
’s of all types listed.
Why You Probably Shouldn’t Send To Everyone
When you send an RPC to everyone
this includes the local client that sent it. If you are sending an RPC to create an explosion you might think “I also want the local client to see the explosion!”, but you must consider that RPC’s to yourself also have a network delay.
In the graph above we send an RPC to everyone, and after a delay the event is fired locally.
For gameplay critical things like firing a gun you want to process the event instantly locally instead.
In this example the local client will LogError
immediately.