Skip to main content

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​

  1. In the Asset Browser, create a new Data Table asset (category Logic) and name it Weapons.
  2. A new table always gets a schema of its own: the editor creates WeaponsRow.plDataSchemaAsset next to it, with one example column called Value, and assigns it to the table. You can point the table at a different schema later.
  3. The table window opens. The header shows the file name, the schema (schema WeaponsRow) and no 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.

  1. Open the Schema tab and select the Value column. Rename it to Damage. Tick Validate against a range and set Minimum 0 and Maximum 500.
  2. Press + Column. Name it FireRate, type Float.
  3. Press + Column. Name it Rarity, type Enumeration, and enter Common, Rare, Epic, Legendary in Inline values. Tick Indexed, because the game will look rows up by rarity.
  4. Press + Column. Name it DPS, type Float, tick Derived and enter the expression Damage * FireRate. The line under the field turns green and shows the value for the first row once the expression compiles.
note

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​

  1. Switch to the Rows tab and press + Row. Double-click the key cell and type rifle_mk2.
  2. Fill in Damage 36, FireRate 2.5 and Rarity Rare. The DPS cell shows 90 a moment later.
  3. Add pistol (12, 4, Common) and cannon (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.
  4. 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.
  5. 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.

note

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​

  1. In a Visual Script graph, add the DataTables function GetCell.
  2. Set Table to the table's asset GUID, Key to rifle_mk2 and Column to Damage.
  3. 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​