In this part of the tutorial, you see how RPCs change the game for all affected players, not just the player whose action initiates the change. In the map
Map03_RPCs, you see a target dummy that disappears for all players when it is destroyed, not just for the player that destroyed it.
Watch the video for this part of the tutorial:
Map03_RPCs with the target dummy that can be destroyed by players
RPCs are functions which the client or server use to send messages to each other over a network connection. Where appropriate, the SpatialOS Runtime passes the execution of an RPC to the relevant server-worker instance, and this instance then executes the RPC.
In this example, the client-worker calls the
StartFire function of the `BP_SimpleWeapon` Blueprint.
StartFire then calls the
ServerFire runs on the server and runs a line trace to detect whether the player hit anything. To see it work, shoot the target dummy.
For more information, look in the Blueprints. Note that the target dummy respawns after a while.
To view the RPC tutorial, you need to open the map and restart the game. To do so, follow these steps:
- Open the Example Project in the Unreal Editor.
- In the Content Browser, open InGameTutorial > Maps > Map03_RPCs.
- 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.
Note the following about this map:
- The player characters each have a weapon and can fire on the target dummy (
- The player characters can destroy the target with a single hit.
- The target respawns after a period of time.
- The map Blueprint contains the logic for respawning the target dummy.
In Unreal, RPCs are functions which either the client or the server use to send messages to each other over a network connection. SpatialOS extends this functionality to work in its multi-server environment. Where appropriate, the SpatialOS Runtime passes the execution of an RPC to the relevant server-worker instance, and this instance then executes the RPC.
Map03_RPCs, the player character carries the weapon defined by
InGameTutorial/Blueprints/Weapons/BP_SimpleWeapon. In this Blueprint, there is an RPC called
ServerFire. When a player shoots the dummy, the SpatialOS Runtime runs
ServerFire on the server-worker instance.
ServerFire calls a line trace to check whether the player character hit something when they fired the weapon. If the player character hit the target dummy,
ServerFire also calls
DealDamage, which destroys the dummy.
BP_TargetDummy has its
Replicates property set, so when it is destroyed, it is also destroyed for other players.
BP_SimpleWeapon blueprint. Note the line tracing and the
BP_TargetDummy blueprint. Note that
DealDamage is set to execute on an authoritative server
In the next part of the tutorial, you see an example of how SpatialOS sends Multicast RPCs to all relevant server-worker and client-worker instances.
2020-08-04 Page added with editorial review
Updated about a year ago