Network Events (RPC)

A Remote Procedure Call (RPC) is used to 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.

How it Works

When you send an RPC it travels to the server, then to all receivers. In the image below, 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.

Network events breakdown

Event 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 that is absolutely critical!

Network events: arguments

Supported Types

bool, byte, short, int, long, float, double, string, Vector2, Vector3, Vector4, Quaternion, Color, Color32, DateTime.

Array ’s of all types listed above.

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.

Network events: avoid sending to eeryone

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.

Network events: process events locally

In this example the local client will LogError immediately.