2. Fix common issues

In this section, you fix two problems in the Example Project. These problems demonstrate common issues that you might encounter when you set up offloading in your own projects.

Test the game

  1. Generate a schema (GDK toolbar: Schema).
  2. Generate a snapshot (GDK toolbar: Snapshot).
  3. Start the game (GDK toolbar: Play).

Image: NPC bots in the game

When you test the game, you might notice two issues: one minor problem and one major problem.

  • When an NPC bot kills the game player, the killed message does not state what killed the game player. This is a minor problem.
  • When a game player captures the control point, NPC bots do not respawn on the player’s team as expected. This is a major problem.

These issues are a result of setting up offloading on the Control_Small map.

Fix both of these by following the instructions below.

Fix the missing killed message

When an NPC bot kills the game player, the game should display the killed message Killed by Automated Defenses.

Image: The killed message box does not contain a message

The game’s UI setup determines what message the game displays, based on the ClientInformOfDeath RPC.

ClientInformOfDeath is the last in a sequence of events that begins with ACrossServerPawn::TakeDamage. When an NPC bot shoots the game player, the client-worker instance computing the game player handles TakeDamage in two different ways, depending on whether the game has a single-server setup or uses multiserver offloading.

In a single-server setup, the server-worker instance calls TakeDamage on the game player’s Actor itself and doesn’t have to pass it to any other server-worker instance. It passes the Controller of the NPC bot that shot the player in the AController* EventInstigator parameter. The code uses this parameter to determine what killed the player and display the relevant killed message.

When the game uses multiserver offloading, the call to TakeDamage is a cross-server RPC from the offloaded server-worker instance computing the NPC bots to the main Unreal server-worker instance computing the game player.

The Example Project does not replicate the NPC’s Controller, so the Controller does not exist on the main Unreal server-worker instance that computes the game player. As a result, the Killer argument inside the Death_Implementation RPC has the value nullptr, and Death_Implementation sends a null value to ClientInformOfDeath, resulting in no killed message.

You need to adjust the code to check for a nullptr value and display the relevant killed message.

To do this:

  1. Close the Unreal Editor.
  2. Open the Example Project (GDKShooter.sln) in Visual Studio.
  3. Search the solution for the function UControllerEventsComponent::Death_Implementation.
  4. Replace the function with the code below.
    When you paste this code, you add the //Offloaded NPC section of code to the function.
void UControllerEventsComponent::Death_Implementation(const AController* Killer)

	if (Killer != nullptr)
		APlayerState* KillerPlayerState = Killer->PlayerState;
		if (KillerPlayerState != nullptr)
			   ClientInformOfDeath(KillerPlayerState->GetPlayerName(), KillerPlayerState->PlayerId);
			ClientInformOfDeath(TEXT(""), -1);
	else //Offloaded NPC
		ClientInformOfDeath(TEXT(""), -1);
  1. In the Visual Studio toolbar, select Local Windows Debugger (or press F5 on your keyboard) to open the Example Project in the Unreal Editor.
  2. In the GDK Toolbar, select Play.
  3. When one of the NPC bots kills the game player (you!), you see the following message:

Image: The correct killed message

Fix NPC bot respawning

When the game player captures the control point, the NPC bots should respawn and join the game player’s team.

In the game’s project code, to make this happen BP_ControlPoint runs on the main Unreal server-worker instance: it updates the UTeamComponents to set the team of any Actors in UpdateAttachedTeamComponents.

However, with multiserver offloading set up, this code runs on a different server-worker instance to the offloaded NPC server-worker instance which computes the NPC bots. This means the NPC server-worker instance never updates UTeamComponents.

You could solve this in two ways:

  • Make UTeamComponent::SetTeam into a Cross-server RPC, so the NPC offloaded server-worker instance executes the method to set the team.
  • Read the value in BP_ControlPoint::ControllingTeam when the NPC bots respawn.

For this tutorial, you will read the value when the NPC bots respawn.

Because BP_ControlPoint::ControllingTeam is a replicated property, the SpatialOS Runtime replicates its value to the NPC offloaded server-worker instance. This means BP_ControlPoint::ControllingTeam provides the correct value.

To set this up:

  1. In the Unreal Editor’s Content Browser, open the Blueprint for NPCSpawner.
    (In the Content Browser, go to Content > Blueprints > NPCs > NPCSpawner)
  2. Add a new variable with the following properties:
    • Variable Name: Control Point
    • Variable Type: BP Control Point
  1. Use the EventGraph to open Event BeginPlay and find the comment If Authority & Enabled, Cache Spawn Points and Start Wave Timer.
    a. Add the nodes highlighted in red in the image below.
    b. Connect the existing SET node to the input of Cast to BP_ControlPoint.

Image: Add these nodes to BeginPlay

  1. Use the EventGraph to open SpawnWave and find the comment Spawn Wave of NPCs up to MaxSpawnedNPCs.
    a. Set up the nodes highlighted in red in the image below. To set up these nodes, you must remove the following nodes: Get Team, Has Team and both existing Team nodes.
    b. Connect the new Select node to Team in SpawnActor Character NPC as shown below.

Image: Set up these nodes in SpawnWave

  1. In the Blueprint Editor toolbar, select Compile.
  2. Save and close the Blueprint.
  3. Now run the game (in the GDK Toolbar, select Play).

In the game, when you capture the control point, any NPC bots you kill join your team.

You've successfully set up offloading in the Example Project.

2020-06-19 Page updated with editorial review: rewrite for new tutorial
2020-02-24 Page added with editorial review

Updated about a year ago

2. Fix common issues

Suggested Edits are limited on API Reference Pages

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