🚀
Netick
HomeDownloadDiscord
  • Understanding Client-Server Model
  • Core Concepts
  • Network State
  • Change Callback
  • Remote Procedure Calls (RPCs)
  • RPCs vs Properties
  • Listening to Network Events
  • Understanding Client-Side Prediction
    • Writing Client-Side Prediction code
  • Interpolation
  • Lag Compensation
  • Network Object Instantiation and Destruction
    • Network Prefab Pool
  • Parenting
  • Managing Netick
  • Script Execution Order
Powered by GitBook
On this page

Was this helpful?

Remote Procedure Calls (RPCs)

RPCs are method calls on Network Behaviors that are replicated across the network. They can be used for events or to transfer data.

An important use of RPCs is to set up the game and send configuration messages. Use reliable RPCs for things like that.

An RPC example:

[Rpc(source: RpcPeers.Everyone, target: RpcPeers.InputSource, isReliable: true, localInvoke: false)]
private void MyRpc(int arg1)
{
    // Code to be executed
}

You use the [Rpc] attribute to mark a method as an RPC.

  1. RPCs are not called on restimulated ticks.

  2. By default all RPCs are unreliable.

RPC method constraints:

  • Must have the return type of void.

  • Must only include parameters that can be networked. Same ones as the properties

[Rpc] attribute parameters

  • Source: the peer/peers the RPC should be sent from

  • Target: the peer/peers the RPC will be executed on

  • isReliable: whether the RPC is sent reliably or unreliably

  • localInvoke: whether to invoke the RPC locally or not

Source and target can be any of the following:

  • Owner (the server)

  • Input Source: the client which is providing inputs for this Network Object

  • Proxies: everyone except the Owner and the Input Source

  • Everyone: the server and every connected client

Source Connection of RPCs

If you need to know which connection (a client, or the server) the current RPC is being executed from, you can use Sandbox.RpcSource

[Rpc(source: RpcPeers.Everyone, target: RpcPeers.InputSource, isReliable: true, localInvoke: false)]
private void MyRpc(int arg1)
{
    var rpcSource = Sandbox.RpcSource;
}
PreviousChange CallbackNextRPCs vs Properties

Last updated 1 year ago

Was this helpful?