4. Multicast RPCs

In this part of the tutorial, you learn about how SpatialOS sends Multicast RPCs to all relevant server-worker and client-worker instances.

Watch the video for this part of the tutorial:

Image: In Map04_MulticastRPCs, when one of the players shoots the target dummy, all of the players can see the explosion.

4 - Multicast RPC
A server-worker instance with write access authority over a component can call a Multicast RPC to send messages to other worker instances. The SpatialOS Runtime delivers the RPC to all server-worker and client-worker instances that have interest in this component of the entity.

In this example, the BP_TargetDummy Actor subscribes to the DamageTaken event of the HealthComponent. It uses this event to spawn the explosion emitter. All client-workers receive the event.

To view the Multicast RPCs tutorial, you need to open the map and restart the game. To do so, follow these steps:

  1. Open the Example Project in the Unreal Editor.
  2. In the Content Browser, open InGameTutorial > Maps > Map04_MulticastRPCs.
  3. Make sure you restart your local deployment: in the GDK toolbar, click Stop Deployment. In the Unreal toolbar click Play to restart your game with this map information.

Multicast RPCs in SpatialOS

A server-worker instance can call a Multicast RPC to send messages to other worker instances. In native Unreal, a Multicast RPC runs on one server and all game clients. With SpatialOS, a Multicast RPC runs on the following worker instances:

  • The initiating server-worker instance.
  • All server-worker and client-worker instances that currently have interest in the entity that triggered the RPC.

A worker instance has interest in an entity if it needs to have updates or data from that entity. For example, a server-worker instance that handles AI might have interest in any object within a 100m radius of the AI entities that it controls.

In BP_TargetDummy_Map04, when a player shoots the target dummy (InGameTutorial/Blueprints/Dummy/BP_TargetDummy_Map04) they no longer destroy the dummy in a single shot. Instead, the dummy spawns an explosion at its position every time a player shoots it. All players, not just the player who shot the dummy, can see the explosion.

This happens because in the BeginPlay event, the target dummy subscribes to the DamageTaken Multicast RPC, which is defined in the HealthComponent.h file. DamageTaken runs on all worker instances that have interest in the target dummy entity. This includes the client-worker instances for players who are near to the target dummy.

Image: BP_TargetDummy_Map04 Blueprint

In the next part of the tutorial, you see how you can reduce the computational load on the main server-worker by sharing out tasks to other server-workers.

2020-08-04 Page added with editorial review

Updated about a year ago

4. Multicast RPCs

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.