Netcode for GameObjects (Netcode) has two parts to its messaging system: RPCs and Custom Messages. Both types have sub-types that change their behaviour, functionality, and performance. This page will focus on RPCs.
The concept of an
RPC is common not only in video games but in the software industry in general. They're ways to call methods on objects that aren't in the same executable.
At a high level, when calling an
RPC client side, the SDK will take a note of the object, component, method and any parameters for that
RPC and send that information over the network. The server will receive that information, find the specified object, find the specified method and call it on the specified object with the received parameters.
When calling an
RPC, you call a method remotely on an object that can be anywhere in the world. They're "events" you can trigger when needed.
If you call an
RPC method on your side, it will execute on a different machine.
For more information see the wikipedia entry on Remote Procedure Call's.
See the following pages for more information:
There is also some additional design advice on RPC's and some usage examples on the following pages:
Migration and Compatibility
See RPC Migration and Compatibility for more information on updates, cross-compatibility, and deprecated methods for Unity RPC.
A typical SDK user (Unity developer) can declare multiple RPCs under a
NetworkBehaviour and inbound/outbound RPC calls will be replicated as a part of its replication in a network frame.
A method turned into an RPC is no longer a regular method, it will have its own implications on direct calls and in the network pipeline. See Execution Table.
To use RPCs, make sure
[ServerRpc]attributes are on your method
- Your method name ends with
- your method is declared in a class that inherits from NetworkBehaviour
- your GameObject has a NetworkObject component attached
- Make sure to call your RPC method server side or client side (using
- Only accept value types as parameters
Instances of Serializable Types are passed into an RPC as parameters and are serialized and replicated to the remote side.
See Serialization for more information.