Sites

Menu

Multiserver zoning

2: Test changes locally

Step 1: Start SpatialOS and start the game

  1. Start SpatialOS: in Unreal Editor, in the SpatialOS GDK toolbar, select Start. It’s ready when you see SpatialOS Local deployment started!.
  2. Now, start the game: from the Unreal Editor toolbar, click Play to run the game.

As you play the game, notice that health now decrements when you are shot.

Step 2: View your SpatialOS world in the Inspector


Image: A local Inspector showing two server-worker instances (two Unreal servers) managing your game

The Inspector provides a real-time view of what is happening in your SpatialOS world. It’s a powerful tool for monitoring and debugging both during development and when your game is live in production. Let’s use the Inspector to visualise the areas that each of our server-worker instances have authority (that is, read and write access) over.

  1. Access the Inspector at http://localhost:21000/inspector.
  2. In the View tab, check the boxes next to both of the UnrealWorkers.
  3. In the Show me option, select Authority / interest.
    This causes the Inspector to display the areas that each server-worker instance has authority over as two colored zones.
  4. Back in your two Unreal game clients, run around and shoot.
  5. Using the Inspector to track the location of your two players, notice that if you position them in the same area of authority then their shots damage each other, but if they are on different servers, they can’t damage each other. Let’s fix that.


Step 3: Enable cross-server RPCs

To damage a player on a different server, the actor shooting the bullet must send a cross-server RPC to the actor getting hit by the bullet. You will implement this by overriding the TakeDamage (Unreal documentation) function in the GDKCharcter class.

  1. In your IDE, open UnrealGDKExampleProject\Game\Source\GDKShooter\Public\Characters\GDKCharacter.h.
  2. Under line 91, add this snippet:

    UFUNCTION(CrossServer, Reliable)
    void TakeDamageCrossServer(float Damage, const struct FDamageEvent& DamageEvent, AController* EventInstigator, AActor* DamageCauser);
    

    This snippet creates a new UFUNCTION marked with the function tags CrossServer and Reliable (Unreal documentation). The CrossServer tag forces this function to be executed as a cross-server RPC.

  3. In your IDE, open UnrealGDKExampleProject\Game\Source\GDKShooter\Private\Characters\GDKCharacter.cpp.

  4. Replace the TakeDamage function (lines 158-163) with this snippet:

    float AGDKCharacter::TakeDamage(float Damage, const FDamageEvent& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
    {
    	TakeDamageCrossServer(Damage, DamageEvent, EventInstigator, DamageCauser);
    	return Damage;
    }
    
    void AGDKCharacter::TakeDamageCrossServer_Implementation(float Damage, const FDamageEvent& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
    {
    	float ActualDamage = Super::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser);
    	HealthComponent->TakeDamage(ActualDamage, DamageEvent, EventInstigator, DamageCauser);
    }
    

This snippet implements the functionality that was previously contained within TakeDamage as a cross-server RPC called TakeDamageCrossServer.

Because you have changed code in a function, you now need to rebuild your project. Additionally, because you’ve enabled replication for a variable, you need to generate schema. To do this:

  1. Open GDKShooter.sln with Visual Studio.
  2. In the Solution Explorer window, right-click on GDKShooter and select Build.
  3. Open GDKShooter.uproject in the Unreal Editor and click Schema and then Snapshot.

Now let’s test our new cross-server functionality in another local deployment.

TIP: Check out the local deployment workflow page for a reference diagram of this workflow.


Step 4: Deploy the project locally

  1. In Unreal Editor, in the SpatialOS GDK toolbar, select Start. It’s ready when you see SpatialOS Local deployment started!.
  2. From the Unreal Editor toolbar, select Play to run the game.
  3. Using the Inspector to track the location of your two players, notice that you can now shoot between two Unreal servers and cause damage across their boundaries (provided the two players are on different teams!).


Image: Players running and shooting between two Unreal Servers



Now you can upload your game to the cloud.

> Next: 3: Test changes in the cloud




——
2019-08-02 Page updated with limited editorial review: re-number steps.
2019-04-30 Page updated with limited editorial review.

Search results

Was this page helpful?

Thanks for letting us know!

Thanks for your feedback

Need more help? Ask on the forums