2. SpatialOS components

In this part of the tutorial, you will learn how SpatialOS stores Actor and ActorComponent properties in SpatialOS components. You’ll use the Inspector to examine the values stored in these components.

Watch the video for this part of the tutorial:

Image: Map02_Components with three players. Notice the counter value above each player.

2 - SpatialOS components
A SpatialOS entity is made up of components. These SpatialOS components contain properties in which the SpatialOS Runtime stores the data from Unreal Actor and ActorComponent replicated properties. When you examine these SpatialOS components in the Inspector, you can see that there is a 1:1 mapping between an UnrealActor or ActorComponent replicated property and a SpatialOS component property.

In this scene, each player character has a replicated ActorComponent called HealthComponent with a property called CurrentHealth that is updated regularly in the character’s Blueprint. You can see the property value above your character and also in the Inspector. Make sure to try it with more than one player.

To view the SpatialOS components 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 > Map02_Components.
  3. In the GDK toolbar, click Stop Deployment to stop any deployment you are running:
  1. In the Unreal toolbar, click Play:
  1. Play the game and note the changing number above each player character.

SpatialOS components, Unreal Actors and ActorComponents

A SpatialOS entity is made up of components. These components contain properties. The GDK for Unreal stores the data from Unreal Actor and ActorComponent replicated properties in these components’ properties.

There is a 1:1 mapping between an UnrealActor or ActorComponent replicated property and a SpatialOS component property. A SpatialOS entity (and the components inside it) is effectively a data representation of all replicated properties of an Actor (and the ActorComponents inside it).

In this map, the player character blueprint (InGameTutorial/Blueprints/Characters/BP_Map02_PlayerCharacter) randomly changes the value in HealthComponent. This damages or heals the character at random.

  • The game uses the CounterWidget to show each player’s current health.
  • The CounterWidget is bound to the HealthComponent’s CurrentHealth function.
  • The HealthComponent is a replicated component.

Image: The HealthComponent settings, including replication.

The health counter value

Each player in the game can see the counter value of the other players. The players’ counter values update at different intervals, to help you easily see that the values are different for each player. You can also view the value of the SpatialOS counter component in the Inspector.

  1. From the GDK toolbar, click Inspector.
  2. In the top bar of the Inspector, click Comprehensive view > [Default] World view.
  3. In the Viewport, click a player entity.
  4. In the drop-down list at the top of the Entity details module, select the player entity BP_Map02_PlayerCharacter_C:
  1. In the Components list, search for health and expand the unreal.generated.bpmap02playercharacterc.subobjects.Health component.
    You can now see the component’s currenthealth value:

Image: Health component information in the Inspector’s Entity details window. Note the currenthealth property

In the next part of the tutorial, you see how changes initiated by one player in SpatialOS affect other relevant players.


2020-08-04 Page added with editorial review

Updated about a year ago



2. SpatialOS components


Suggested Edits are limited on API Reference Pages

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