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:
- Open the Example Project in the Unreal Editor.
- In the Content Browser, open InGameTutorial > Maps > Map02_Components.
- In the GDK toolbar, click Stop Deployment to stop any deployment you are running:
- In the Unreal toolbar, click Play:
- Play the game and note the changing number above each player character.
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
CounterWidgetto show each player’s current health.
CounterWidgetis bound to the
HealthComponentis a replicated component.
HealthComponent settings, including replication.
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.
- From the GDK toolbar, click Inspector.
- In the top bar of the Inspector, click Comprehensive view > [Default] World view.
- In the Viewport, click a player entity.
- In the drop-down list at the top of the Entity details module, select the player entity
- In the Components list, search for
healthand 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
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