For the complete documentation index, see llms.txt. This page is also available as Markdown.

Messaging and RPCs

Summary

How Reactor sends discrete events with remote procedure calls: room RPCs, entity RPCs, and batch entity RPCs, including targeting and delivery. It is part of the Reactor Technical Overview.

Properties Versus RPCs

Properties sync continuous state and always hold the latest value. RPCs send one-off events: "took damage", "match started", "played a sound". Reach for a property when a client needs the current value at any time, and an RPC when something happens once and the moment matters. Both properties and RPCs carry their data as ksMultiType.

Defining a Handler

Tag a method with [ksRPC(id)] on a room or entity script. The id is a unique number that both sides agree on. A handler can take a ksMultiType[], or it can list specific parameter types that ksMultiType converts to:

[ksRPC(RPC.DAMAGE)]
public void OnDamage(ksMultiType[] args) { /* ... */ }

[ksRPC(RPC.DAMAGE)]
public void OnDamage(uint attackerId, float damage) { /* ... */ }

Handlers run on the main thread.

Room RPCs

A room RPC invokes methods tagged with [ksRPC(id)] in room scripts. Call it on the server to reach clients, or on the client to reach the server:

Use room RPCs for events that concern the session rather than a single object.

Entity RPCs

An entity RPC invokes methods tagged with [ksRPC(id)] on the targeted entity's scripts. On the server it reaches the players who can see that entity; on the client it reaches the server:

Use entity RPCs for events tied to one object, such as a hit reaction or an animation trigger.

Batch Entity RPCs

A batch entity RPC calls the same RPC on many entities in one message. It encodes the entity list once with a single id and shared arguments, which costs less than one call per entity:

Reach for a batch RPC when one thing happens to a group at once, such as every enemy in range taking damage. The receiving client or server unpacks the batch and raises the call on each entity, so a receiving handler looks the same as for a single entity RPC.

Arguments and Delivery

  • Arguments: values carried as ksMultiType.

  • Direction: client to server, and server to client.

  • Delivery: reliable and in order over the connection.

  • Cluster RPCs: a separate attribute sends RPCs room to room across a cluster, and these are the only RPCs that may run off the main thread. See Room-to-Room Data and RPCs.

Targeted server calls skip virtual players, since a bot has no client to receive them.

Where to Go Next

Last updated