Data tables

A data table is a table of values based on a structure. It can be used to represent a spreadsheet document. This is useful for data-driven gameplay where game data needs to be constantly modified and balanced. In these cases, the data can be modified in a Spreadsheet Editor, and then imported into the game.

To create a data table, click the Add New button in Content Browser, and in the Miscellaneous submenu, select Data Table, as shown in the next screenshot:

After selecting Data Table, the Unreal Editor will ask you to choose a structure that represents the data type of the table. The next screenshot shows that the data table will be created based on the Weapon Type structure:

Give a name to the data table created and double-click it to open the Data Table Editor. The next screenshot shows a data table named WeaponTable with some sample data. Click the + icon to add a row to the table. Each row has Row Name that identifies the row, so this Row Name must be unique. In the screenshot example, the Row Name is a simple index:

The data table can also be imported from a plain text comma-separated values (CSV) file. The next screenshot shows an example of a CSV file. A Spreadsheet Editor can export a spreadsheet to the CSV format:

To import a CSV file, click the Import button of Content Browser and select the CSV file. A dialog box will appear, asking you to select a structure in the field Choose DataTable Row Type, as shown in the following screenshot:

To use a data table in a Blueprint, create a variable in the Blueprint Editor and select Data Table as Variable Type. Compile the Blueprint, and in Default Value, select one data table, as shown in the following screenshot:

The following screenshot shows some Actions to get data from a data table:

  • Get Data Table Row: Returns a structure with the data of a specific row
  • Get Data Table Row Names: Copies all the Row Names of a data table to an array
  • Get Data Table Column as String: Copies all the values of a column to an array of strings:

The following screenshot shows an example usage of a data table. Select Weapon is a function that receives Weapon ID as an input parameter and searches in Weapon Table for a weapon whose Row Name is equal to Weapon ID. If it finds the weapon, then it copies the weapon data to the Current Weapon variable:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset