Tiny Town

Create & Implement new blocks

This tutorial will show you how to add new blocks, edit their individual stats and customise their appearance and behaviour. We will assume here that you understand what a block is, if not check out What is a block?.

Step 1: Open the database

Most of the meta content for your game will be stored in a data table. The template comes with a table already implemented that you can open and edit. The asset is located in Content/Data/ and is named Data_Block. 


If you prefer editing it in a spreadsheet editor and importing it manually, you can also download a blank template here. Once the data table saved as a .CSV file, make sure to import it via the editor in Content/Data/, and name it Data_Block. The struct to use when importing is called "FStrucBlock".


For more information about data tables in Unreal Engine check this guide.

Capture d’écran (137).png
Capture d’écran (136).png

Step 2: Understanding the table

Once the table open, each row represent a block. Every column represents an editable element. This following is a break down of all the elements that you can customise from the data table:

Row Name: This should be a number, order of the blocks doesn't matter code wise.

Block Name: This value is used to identify blocks for the player (doesn't matter code wise).


Description: Same as Block Name.


Category Name: This is used by the template to sort buildings and expose the data in nice way in blueprints. When it comes to Zone Buildings, this is used to associate a Zone Building to a Zone (Category should correspond to the zone's name).

Size X and Y: The block's size in tiles.

Block Type: This specifies to the template how certain block should behave (see
What is a block).


Icon: Same as Block Name.


Block Class: The class to use when spawning the block.


Grid Colour: In the current setup this is used to give zones their colour.

Capture d’écran (448).png

Step 3: Create a new block blueprint

All blocks are child classes of TT_Block, this enables then to all inherit their stats from the data base on spawn. However, we can customise a block even further by creating a child blueprint class  for each block. This allows us add meshes, lights, particle effects and custom logic for each block.


So to implement a new block we need to create our child blueprint class like shown on the right. Once created we need assign this class to the corresponding row in the data table. This can be done both in the spreadsheet editor by inputing a path or via Unreal Engine's data table editor like shown below.

NOTE: If you are setting the class via a spreadsheet editor, the path should look like that:

Capture d’écran (131).png
Capture d’écran (139).png
Capture d’écran (138).png

Step 4: Customise the block

Once the blueprint create you can now implement custom logic, add meshes, lights and particle effects as you would with any other blueprints. This class inherits two important components:

BoxComp: This box represents the block's hit box and allows the player to select it in the world. Having the collision managed by an external collision box can be useful in the case the block contains multiple meshes/skeletal meshes.

BlockMesh: This is where your mesh goes. Make sure to size it right, and to disable collisions. However if you don't want to use it you don't have to, simply add the components of your choice. Any additional components will need to be attached to the RotationRoot component.

To size the block correctly in regards to the grid, you can add the GridManager object as a ChildActorComponent and set it to the correct size. 

Capture d’écran (373).png
Capture d’écran (374) - Copie.png

To help you implement your custom logic, there several useful function in the block's class:

GetBlockManager() and GetGridManager()

GetBlockData(): Returns a copy of the data table row for this block.

GetOccupiedTilesIds(): Returns the tile IDs of the tiles occupied by this block on the grid.

isInEditingMode: Returns whether the block is being placed down (true) or has been placed down already (false).

EventOnDestroyBlock: Is called whenever a block is being deleted. The parent call takes care of deleting it via C++, but you can add some custom logic in between.

Capture d’écran (375).png

You should now all be set to add new blocks to your game! 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.