Tiny Town

Accessing the data table

In this tutorial, we'll show you how to access the data stored in the data table from blueprints. There are multiple places the data about blocks are stored, you can access from the blockmanager object, from the blocks themselves, and you can also get it from the data table itself.

From the blocks object

Whenever a block is spawned by the player, its corresponding data is copied over from the data base. This means you can access a block's data from the block itself. The node GetBlockData() will return all the data from the data table corresponding to the block it was called in. You can then right clicking on the output pin and selecting "Split Struct Pin" to display every variable.

Capture d’écran (146).png

From the blockmanager

Step 1: Getting the Blockmanager

Whenever the game is launched, an instance of the blockmanager class will be spawned to read the data table and organise the data. You can get a reference to the blockmanager with the function GetBlockManager() in the PlayerGridCamera pawn class, in any Block objects and from the GridManager. 

There will always be one BlockManager object per GridManager, this means you can also get a reference to it via GetAllActorOfClass().

Capture d’écran (144).png

Step 2: Get a reference to a block

Once you have a reference to the BlockManager, you will need to get a reference to a specific block. Every block is referenced via its block ID which corresponding to its Row number in the data table. 

The BlockManager organises every block by Category_Name (set in the data table). The list of all the blocks sorted by category are accessible via GetAllBlocksSortedByCategory(). You can get the zones only via GetAllZones() and the zone buildings only via GetAllZoneBuildings()

All three of these functions will return a block ID alongside a name for the block. For GetAllBlocksSortedByCategory(), and GetAllZones() the name corresponds to the name of the block. However, for GetAllZoneBuildings(), the name corresponds to the zone the building is associated with. For more information on blocks and zones see here.

Capture d’écran (144).png

Step 3: Get a block's data

Once you have a block ID to look for, you can use GetBlockStatsInDataTable() to access the block's data. By right clicking on the output pin and selecting "Split Struct Pin", you'll get access to all the variables as shown on the right.

Capture d’écran (145).png

From the data table

You can also access directly the data table from blueprints by using the node GetDataTableRow(). The row to input will the block ID of the block you want the data from.

Capture d’écran (148).png

You should now all be set to access the data table in your blueprints! If you have any questions about this tutorial, you can post them in the Marketplace comments or e-mail me at: samuel.metters@gmail.com.