Getting started
This page builds a small weapon table, fills it with rows, and reads one row from C++, from a component property and from Visual Script. It takes about ten minutes.
1. Create the table
- In the Asset Browser, create a new Data Table asset (category Logic) and name it
Weapons. - A new table always gets a schema of its own: the editor creates
WeaponsRow.plDataSchemaAssetnext to it, with one example column calledValue, and assigns it to the table. You can point the table at a different schema later. - The table window opens. The header shows the file name, the schema (
schema WeaponsRow) andno set, because the table is not part of a table set yet.
2. Define the columns
Columns are defined in the schema, and the Schema tab of the table window edits that schema in place.
- Open the Schema tab and select the
Valuecolumn. Rename it toDamage. Tick Validate against a range and set Minimum 0 and Maximum 500. - Press + Column. Name it
FireRate, type Float. - Press + Column. Name it
Rarity, type Enumeration, and enterCommon, Rare, Epic, Legendaryin Inline values. Tick Indexed, because the game will look rows up by rarity. - Press + Column. Name it
DPS, type Float, tick Derived and enter the expressionDamage * FireRate. The line under the field turns green and shows the value for the first row once the expression compiles.
Note
Every schema edit is saved to the schema asset right away and the grid follows it. Other tables that use the same schema see the change too. The Schema tab lists how many tables and store tables use the schema.
3. Add rows
- Switch to the Rows tab and press + Row. Double-click the key cell and type
rifle_mk2. - Fill in Damage 36, FireRate 2.5 and Rarity Rare. The DPS cell shows 90 a moment later.
- Add
pistol(12, 4, Common) andcannon(90, 0.5, Epic) the same way, or copy three rows from a spreadsheet and press Ctrl+V on the first empty row: pasting past the last row adds rows. - Select a row to see it in the inspector on the right: one typed editor per column, and statistics for the grid's current column below.
- Save (Ctrl+S). The status bar at the bottom changes to transform up to date.
4. Read a row from C++
Tables are loaded like every other resource. Refer to the table by its asset GUID: right-click the table in the Asset Browser and choose Copy Asset Guid.
#include <GameEngine/DataTables/DataTableResource.h>
plDataTableResourceHandle hWeapons = plResourceManager::LoadResource<plDataTableResource>("{ 4ec80001-6d67-1bc1-0100-64a7b3b6e00d }");
plResourceLock<plDataTableResource> pWeapons(hWeapons, plResourceAcquireMode::BlockTillLoaded);
if (plDataRowView row = pWeapons->GetRow("rifle_mk2"))
{
const float fDamage = row.Get<float>("Damage"); // 36
const float fDps = row.Get<float>("DPS"); // 90, computed when the table was saved
}
A missing key returns an invalid view, so the if above is all the error handling a lookup needs. C++ runtime covers faster column access, queries and hot reload.
5. Point a component at a row
Give the component a plDataRowRef property. The plDataRowRefAttribute tells the editor which tables to offer: here, every table that uses the WeaponsRow schema.
#include <GameEngine/DataTables/DataRowRef.h>
class plWeaponPickupComponent : public plComponent
{
// ...
plDataRowRef m_Weapon;
};
PL_BEGIN_COMPONENT_TYPE(plWeaponPickupComponent, 1, plComponentMode::Static)
{
PL_BEGIN_PROPERTIES
{
PL_MEMBER_PROPERTY("Weapon", m_Weapon)->AddAttributes(new plDataRowRefAttribute("Data/WeaponsRow.plDataSchemaAsset")),
}
PL_END_PROPERTIES;
}
PL_END_COMPONENT_TYPE
// Serialize it like any other value: s << m_Weapon; / s >> m_Weapon;
void plWeaponPickupComponent::OnSimulationStarted()
{
if (plDataRowView weapon = m_Weapon.Lookup())
{
m_fDamage = weapon.Get<float>("Damage");
}
}
In the property grid the Weapon property shows Weapons / rifle_mk2. Clicking it opens the row picker: a table selector, a search box and the rows with their preview columns. A reference whose row no longer exists is drawn in red. The arrow button next to it opens the table with that row selected.
Tip
The schema argument accepts the schema asset's GUID or its path relative to a data directory. Leave it empty to offer every table in the project.
6. Read a row from Visual Script
- In a Visual Script graph, add the DataTables function GetCell.
- Set Table to the table's asset GUID, Key to
rifle_mk2and Column toDamage. - The output is a variant holding 36. Connect it to whatever needs the value.
The full list of script functions is in Scripting & tools.
Where to go next
- Filter the table by rarity or damage, bulk-edit a column, fix what the Validation tab reports: The table window.
- Keep a spreadsheet as the source of truth: Import, linked sources & sets.
- Keep the player's inventory in the save game: Data store & saving.