Skip to content
Ryan edited this page Jun 20, 2020 · 1 revision

Remote Procedure Call (RPC)

An RPC allows you to tell the clients/server to run a specific method on another object. Since RPCs are fairly complicated I suggest reading this Entire document before using them.

Setup is similar to a NetworkField so if you are confused after reading this, perhaps also give that a read.

A NetworkObject component is attached to objects created over the network if they don't already have one. However if you give a prefab one, you can give it custom behaviours.

Creating an RPC

First we have to define an RPC for the prefab so everyone knows what it is. Simply do that by going to NetworkObject and adding an RPC to the "Rpcs" list variable.

You will have to name it, say if only the server can call it, and add to it's UnityEvent a method(s) that runs when it gets called.

Setting up an RPC Method

RPC methods must take in "RPCArgs" as a parameter. Even if you aren't passing parameters you should still have it.

For this lets say we define it as RPCArgs args.

RPCArgs has RPCArgs.GetNext(); which will return an object of . You must GetNext in the order you passed the variables when calling.

You must attach these methods to OnRPC in the RPC located in the NetworkObject.

Calling an RPC

Calling an RPC is fairly simple. You must run NetworkObject.CallRPC(rpcName,sendType,any params go after);

  • rpcName is a string and what you named the RPC
  • sendType is the packet send type, see packet types for more information.
  • Any params can go after, you don't need any but you can put some if required.
Clone this wiki locally