Skip to main content

Execution Table

The following table details the execution of ServerRpc and ClientRpc functions:

FunctionServerClientHost (Server+Client)
ServerRpc Send
ServerRpc Execute
ClientRpc Send
ClientRpc Execute

An RPC function never executes its body immediately since the function call really is a stand-in for a network transmission. Even a ServerRpc called by a host (an instance that is a client and the server at the same time, or listen-server) will not be executed immediately. It will instead follow the regular network frame staging first and queued-up to be executed locally in the next network frame.

Structure of a typical ServerRpc:

[ServerRpc]
void MyServerRpc(int somenumber, string somestring)
{
// Network Send Block (framework-code)
// Network Return Block (framework-code)
// RPC Method Body (user-code)
}

Pseudo-code sample of a ServerRpc:

[ServerRpc]
void MyServerRpc(int somenumber, string somestring)
{
// --- begin: injected framework-code
if (NetworkSend())
{
// this block will be executed if:
// - called from user-code on client
// - called from user-code on host
var writer = NetworkCreateWriter();
writer.WriteInt32(1234567890); // RPC method signature hash
writer.WriteInt32(somenumber);
writer.WriteChars(somestring);
NetworkSendRpc(writer);
}
if (NetworkReturn())
{
// this block will be executed if:
// - called from user-code
// - called from framework-code on client
return;
}
// --- end: injected framework-code
print($"MyServerRpc: {somenumber}");
}
Example banner
Client can invoke a server RPC on a Network Object. The RPC will be placed in the local queue and then sent to the server, where it will be executed on the server version of the same Network Object.
Example banner
Clients can invoke server RPCs on Client Hosts the same way they can invoke server RPCs on the regular servers: the RPC will be placed in the local queue and then sent to the Client Host, where it will be executed on the Client Host's version of the same Network Object.
Example banner
When a server RPC is invoked by the Client Host, the RPC will be placed in a local queue and then executed on the Client Host after a short delay. The same happens for pure servers.
Example banner
Example banner
Client Hosts can invoke Client RPCs on Network Objects. The RPC will be placed in the local queue and then, after a short delay the client RPC will be executed on the Client Host, and sent to the other clients. When client RPC is received by the client - it is executed on the Client's version of the same Network Object.