In the following tutorial, I'll show you most of the concepts involved in the creation of building logics.
Create your blueprint BuildingLogic by overriding the c++ BuildingLogic class.
First Step : We override the SpawnContentInCellBP event. And we get the informations of the current cell.
Step 02 : Let's use the Category setting to determine if we want to spawn something inside the cell. Here we get the cell location by using the GetCellLocation function and we spawn the floor actor inside the cell by using the SpawnAndRegisterActor function.
Make sure you are using the right BuildingLogic for you Dungeon.
Let's also add those layers, categories and tags under LayoutSettings.
At this point you should be able to paint the floor of the cells. Under Category, select "Room" and make sure that you have selected the "Base" layer.
Step 3 : Now, let's make some walls ! I have grabbed the EmptyDirs node from the cell infos to get the directions to which the cells has no neighbors (in world space).
Note that two cells with different GroupIDs won't be considered as neighbors. You can use this to delimitate the rooms inside the Dungeon.
Now if you click on the "RespawnAllCellContent" button you'll see the walls appear.
If you try to paint some cells with a different GroupID, you'll see that walls will appear between the different goups.
Ok. Now let's make the doors.
We will move some stuff inside functions. Create a PlaceWall() and a PlaceDoor() functions. Those two function will be the same except that they will spawn different Actors.
Let's also add a ShouldPlaceDoor() function. This one will check if the cell in the given direction has the tag "Door".
Now that we have made the functions, let's modify the last part of the graph. I have dragged the pink wire from the CellTag pin in the cellInfos.
Now when you tag two adjacent cell with the "Door" tag, this will create a door between the two cells.
Note that you can use the little round button at the left to force the tool to edit only one setting inside the cell.
Let's place some pillars in walls intersections.
Create a PlaceWallCorner() function :
Place this function inside the graph. We place a sequence node to add this logic in parallel of the wall/door logic.
Here, the green wires are dragged from the ExternalCornerDirs and InternalCornerDirs of the CellInfos.
Now, if you click on the "RespawnAllCellContent" button, you'll see those pillars appear at the walls intersections.
I'll show you how to add layers and play with them inside the BuildingLogics.
Layers need to be used if you want to apply multiple settings inside the same cell. For example if you want to add a ceiling inside a cell which already contains informations requested for the creation of a floor. You can add extra infos about the ceiling to spawn by using an addditional "Ceiling" layer.
That's what we will cover in the next part.
First of all, you need to add a new layer to the layers list.
Let's call it "Ceiling".
Then, let's add those node at the beginning of the graph.
GetLayerNameFromIndex() let's you get the name of the layer. You can directly work with the layer index, but using names instead can be more convenient.
In the example, if we detect that you are editing a cell inside the "Base" layer, we will route the logic to the one we have already created in the previous part.
But if the current layer is "Ceiling" we will apply another logic.
Note : The SpawnContentInCellBP() event is call for each cell and for each layer. So editing a cell which uses two layers will result in two event calls. One for each layer.
Here we apply a simple logic for the Ceiling layer : We simply spawn a Ceiling inside the cell.
Now, if you paint something inside the Ceiling layer, you'll spawn the ceiling inside the cell.
Note that you can paint inside multiple layer at a time. Just check the checkbox of all the layers you want to edit. The little round button allows you to select only one layer and deselect the others.
A very nice little feature that I've added to layer is the ability to hide them. Simply check the Hide checkbox in the layer list to hide one or more layer(s).
This can be really convenient with things like ceiling.
That's all for this tutorial.
I strongly recommend you to check the Demo project to see more example. You can directly use those example inside your own projects if you want.
Note that in the Demo project, I use some utility fonctions wich will get the meshes to spawn inside a DataTable. This is a nice approach which allows you to change the meshes from inside a single data table instead of openning your building logic each time you want to replace meshes.