Workflow: Creating a Fact Schema
A Schema is the foundation of your data. It acts as a contract, defining every Fact that a runtime Context will contain. This guide will walk you through the four essential steps to create and register a new Schema.
We will create a simple Schema for a player character, defining their health and a boolean flag for whether they are carrying a key.
Step 1: Define Gameplay Tags
Every piece of data in FactsDB is identified by a Gameplay Tag. Before we create any assets, we must define the tags we'll need. It's crucial to establish a clear and consistent hierarchy.
-
Go to
Edit
>Project Settings
>Project
>Gameplay Tags
. -
Click "Manage Gameplay Tags".
-
Add the following tags. The dot notation
.
automatically creates the hierarchy.Schema.Player
(This will identify our new Schema)Fact.Player.Stat.Health
Fact.Player.Stat.MaxHealth
Fact.Player.State.HasKey
A good tag hierarchy is your best friend. A common pattern is:
Root.Category.SubCategory.SpecificName
Schema.*
for SchemasFact.*
for FactsContext.*
for Context PrefixesQuery.*
for Queries
Step 2: Create the Fact Definition DataTable
Now we will create the Data Table that holds the actual definitions for the Facts in our Schema.Player
.
- In the Content Browser, right-click and select
Miscellaneous
>Data Table
. - In the "Pick Row Structure" dialog, select
FactDefinition
. This is critical. - Name the new asset
DT_PlayerFacts
. - Open
DT_PlayerFacts
. We will now add a row for each Fact in our schema. - Click "Add" to create a new row.
Defining the Health Fact
- Row Name: Can be left as default.
- Tag: Select
Fact.Player.Stat.Health
from the dropdown. - DefaultValue:
- Click the
+
icon next to DefaultValue. - Search for and select the
Fact Float
struct. This is the wrapper forfloat
values. - Set the
Value
inside theFact Float
to100.0
.
- Click the
- bReplicate: Leave this checked (true) so health is networked.
Defining MaxHealth and HasKey
Repeat the process for the other two facts:
- Row 2:
Player.Stat.MaxHealth
- Tag:
Fact.Player.Stat.MaxHealth
- DefaultValue:
Fact Float
, Value =100.0
- Tag:
- Row 3:
Player.State.HasKey
- Tag:
Fact.Player.State.HasKey
- DefaultValue:
Fact Bool
, Value =false
- Description: (Optional) Add a helpful note like "True if the player is currently holding the dungeon key."
- Tag:
Save the Data Table. You have now defined the structure and default state for your player's data!
Step 3: Register the Schema in Project Settings
The system needs to know that DT_PlayerFacts
belongs to the Schema.Player
. We do this in the project settings.
- Go to
Edit
>Project Settings
. - Navigate to the
Game
>FactsDB
section. - Under Fact Schema Definitions, click the
+
to add a new element to the map. - Schema Tag: Select the
Schema.Player
tag we created. - Fact Data Tables: Click the
+
to add an element to the array, and select ourDT_PlayerFacts
Data Table.
Step 4: (Optional) Configure Schema Inheritance
Our Schema.Player
is a base schema. Imagine we wanted to create a "Hard Mode" player schema that starts with less health. Instead of duplicating the Data Table, we can use inheritance.
- Add a new tag:
Schema.Player.HardMode
. - Create a new, smaller Data Table, e.g.,
DT_PlayerFacts_HardMode
. - In this new table, add only one row that overrides the health:
- Row Name:
Player.Stat.Health
- Tag:
Fact.Player.Stat.Health
(Must be the same tag to override) - DefaultValue:
Fact Float
, Value =50.0
- Row Name:
- In Project Settings, add a new Schema Definition for
Schema.Player.HardMode
. - Set its Parent Schema to
Schema.Player
. - Add
DT_PlayerFacts_HardMode
to its own Fact Data Tables array.
Now, any component using Schema.Player.HardMode
will inherit MaxHealth
and HasKey
from Schema.Player
, but will use the overridden Health
value of 50.
With the Schema defined and registered, the next step is to bring it into the game world by adding a UFactsComponent
to an Actor.
Next Up: Using Facts in Actors