Skip to main content
Version: Next (dev)

Schemas and column types

A Data Schema asset is the row type of one or more tables. It is an ordered list of columns. Each column has a name, a type, flags, an optional default and validation rules. Tables, table sets, store tables and the generated C++ headers all read the same schema, so a column is defined once.

Edit a schema from the Schema tab of any table that uses it, or open the schema asset on its own. Both edit the same document.

Column types​

The set of types is fixed, so that every column packs into a fixed-width runtime array and every type has a grid editor, a text form for CSV and the clipboard, and a script mapping.

TypeHoldsText form (CSV, clipboard)C++ read
Booltrue or falsetrue / false / 1 / 0GetBool, Get<bool>
Int32-bit signed integer42GetInt, Get<plInt32>
Float32-bit float1.25GetFloat, Get<float>
NameA short identifier, stored hashedfire_damageGetName → plHashedString
StringAny textany textGetString → plStringView
TextPlayer-facing text, translated on read. See Text columns.the source-language textGetText → translated plStringView
EnumerationOne value of a reflected enum type, or of an inline listthe value name: EpicGetInt
FlagsAny combination of a reflected bitflags type, or of an inline listFire|IceGetUInt
TagsA set of tagsWeapon.Ranged;HeavyGetTags, HasTag
Vec2 / Vec3 / Vec4Float vectors(1, 0, 0)GetVec2 / GetVec3 / GetVec4
ColorLinear colour#ffcc00GetColor
TimeA duration, stored in seconds1.5sGetTime → plTime
AngleAn angle, stored in radians, shown in degrees90degGetAngle → plAngle
AssetA reference to an assetasset GUID or pathGetAssetId → resource id to pass to LoadResource
RowA reference to a row of another table (or of the same table)the row key: ammo_762GetRef → plDataRowRef, GetRefRow → the row
CurveA 1D curveJSON: { "Points": [ [0, 1], [1, 2] ] }GetCurve → const plCurve1D*
ArrayA list of one scalar element type: Bool, Int, Float, Enumeration, Flags, Name, String, Text, Vec2, Vec3, Vec4, Color, Time or Angle[a;b;c]GetArrayCount, GetArrayElement
StructA dictionary of named valuesJSON objectGetStruct → const plVariantDictionary*
note

Note

Curve, Array and Struct cells have no compact text form. The grid shows them read-only. Edit them in the inspector's JSON editor or import them from a JSON file. CSV cannot carry them losslessly.

Enumeration and Flags values​

Set Value type to a reflected enum or bitflags type (for example one of your game's enums) to use its values. Leave it empty and enter a comma-separated list in Inline values instead. An inline Enumeration value is stored as its position in the list (the first value is 0), and an inline Flags value is the bit at that position. Reordering an inline list therefore changes what existing cells mean. Append new values at the end.

Column flags​

FlagEffect
RequiredAn empty cell is an error that stops the transform.
UniqueTwo rows with the same value are an error.
IndexedThe transform builds a sorted index, so an equality query on this column is a binary search instead of a scan. Worth it for columns the game filters on often, such as a class or a rarity.
StrictRange, length and pattern violations are errors instead of warnings.
DerivedThe column is computed from Expression and cannot be edited. See below.
Editor ownedFor a table with a linked source file: this column keeps the value authored in the editor instead of taking the file's value, and stays editable in the grid.
AcyclicFor a Row column that points into the same table, such as an upgrade chain: a cycle of references is reported as a warning.
Picker columnThe row picker shows this column next to the key. With no picker columns, it shows the first two ordinary columns.

Column properties​

PropertyApplies toDescription
NameallThe name used by code, scripts, queries and CSV headers. Renaming records the old name, see below.
TypeallOne of the types above. Changing it converts the cells of the current table, see below.
Default valueallThe value of a cell a row does not set. Empty means the type's default (0, false, empty text, white for Color).
Validate against a range, Minimum, Maximumnumeric typesA value outside the range is a warning, or an error when the column is Strict. The Validation tab can clamp all out-of-range cells at once.
Value type, Inline valuesEnumeration, FlagsWhere the values come from, see above.
Asset typeAssetAn asset type filter such as CompatibleAsset_Mesh. A reference to an asset of another type is an error. Empty accepts any asset.
Target tableRowThe table the column's row keys belong to. A key that does not exist there is an error.
Element type, Max countArrayThe element type and the most elements a cell may hold (0 means no limit).
Max length, PatternName, String, TextThe longest allowed text, and a regular expression every value must match completely. Both produce warnings, or errors when the column is Strict.
Tag categoryTagsThe tag category the column's tags come from.
ExpressionDerivedThe formula, see below.
Previous namesallNames the column had before. Filled in automatically on rename.
DescriptionallShown as the column's tooltip in the grid and written into generated code.

Derived columns​

A derived column is computed from the other numeric columns of the same row: Bool, Int, Float, Enumeration, Flags, Time and Angle columns, and derived columns declared earlier in the schema. It must itself have one of those types.

  1. Add a column, give it a numeric type and tick Derived.
  2. Enter the Expression using the other columns' names, e.g. Damage * FireRate or max(Damage - Armor, 1). The expression language is the engine's expression VM, the same one particles and procedural generation use.
  3. The line under the field shows compiles and the result for the first row, or the compile error in red.

The grid and the inspector show derived values shortly after each edit. The values that ship are computed when the table is transformed, so reading a derived column at runtime costs the same as reading any other column. A derived value that is not a finite number, for example after a division by zero, is an error that names the row.

Renaming a column​

Rename a column in the Schema tab. The old name is appended to Previous names and every row of the current table is updated in the same step. The previous names keep everything else working:

  • Other tables that use the schema still find their cells under the old name when they are transformed.
  • CSV and JSON imports match a header against the previous names too.
  • Saved data store rows are matched by previous names when a save game is loaded, so a renamed column keeps its saved values.
warning

Important

Do not delete a column and add a new one to rename it. Saved games and other tables would lose the values.

Changing a column's type​

Changing the Type converts the cells of the table you are editing, as one undo step:

From → ToResult
Int ↔ FloatValues are kept. Float to Int rounds, and the summary says how many values changed.
String or Name → EnumerationText is matched against the value names, ignoring case. Values that match nothing are listed.
anything → StringEach value becomes its text form.
anything elseThe editor asks before it clears the cells that cannot be converted.

Other tables that use the same schema are not converted. The Schema tab lists them. Open each one to convert its cells, otherwise they will report conversion errors on their next transform.

Generated C++ row headers​

A project with a C++ plugin can generate a typed struct per schema. It is opt-in twice: switch it on for the project in Project > Data Tables… > General > Generate code, and tick Generate code for this schema in the Schema tab of each schema that should have a header. Press Generated code in the Schema tab to preview the output.

Saving the schema writes Generated/DataTables/<SchemaName>.h into the C++ plugin's source folder, plus <SchemaName>.schema.json, a manifest for C# tooling. A file whose content has not changed is not rewritten, so saving does not force a rebuild.

// Generated from Data/WeaponsRow.plDataSchemaAsset, do not edit.
struct plWeaponsRow : plDataRowView
{
plWeaponsRow() = default;
plWeaponsRow(const plDataRowView& row) : plDataRowView(row) {}

static constexpr plUInt64 SchemaHash = 0x6A1F...ULL;
bool MatchesSchema() const;

enum Column : plUInt32 { Column_Damage = 0, Column_FireRate = 1, Column_Rarity = 2, Column_DPS = 3 };

float Damage() const { return GetFloat(Column_Damage); }
float FireRate() const { return GetFloat(Column_FireRate); }
plInt32 Rarity() const { return GetInt(Column_Rarity); }
float DPS() const { return GetFloat(Column_DPS); }
};
plWeaponsRow weapon = pWeapons->GetRow("rifle_mk2");

if (weapon.IsValid() && weapon.MatchesSchema())
{
const float fDps = weapon.DPS();
}
warning

Important

The accessors read fixed column positions. Call MatchesSchema() before reading: it compares the table's schema hash with the one the header was generated from. A table built from a changed schema, read through a stale header, would otherwise return values from the wrong columns. The hash changes when a column is added, removed, reordered, renamed or retyped, not when a range, description or pattern changes.

Enumeration columns are generated as plInt32 and Flags columns as plUInt32, with the value type named in a comment, because the generated header cannot include your game's enum headers.