Design a Grid Flow Graph

In the previous section, we used an existing Grid Flow graph from the samples folder. In this section, we'll design one ourselves.

Setup#

Close the Grid Flow Editor, if open

Right click on the Content Browser and choose Dungeon Architect > Grid Flow. This will create a new Grid Flow asset. Rename it to something appropriate and double click to open it in the Grid Flow Editor

Notice that there is only one node in the Execution graph, the Result node. Our final output should be connected to this node

Create Grid#

Right click on an empty area in the Execution Graph and from the context menu select Layout Graph > Create Grid

Connect this node to the Result node and click the Build button in the toolbar

This node creates an initial grid to work with

We'll be designing our layout in this grid. This allows us to work on a higher level abstract graph, making it easier to control the flow. It will then be transferred over to a tilemap

Create Main Path#

Next, we'll create a main path within this grid. The main path has a spawn point and a goal

Create a new node Layout Graph > Create Math Path

Unlink the Create Grid node from the Result node (do this by pressing Alt+LeftClick on the Create Grid Node's border)

Click the Build button. A main path would have been created in the grid

Keep hitting the Build button for different result

note

If you do not see random results when you hit Build, make sure randomize is enabled. Enable this by clicking the Settings button on the toolbar and choosing Editor Settings. Then enabled Randomize Seed

Select the Create Main Path node and inspect the properties

We'll leave everything to default for now

Notice the Path Name parameter is set to main This is the name of the path and we will be referencing this path in the future nodes with this name

You can adjust the size of the path. Start Marker Name and Goal Marker Name lets you specify a name for the markers. You can then create these markers in the theme file and add any object you like. In the sample theme, there's a marker already created with these names and a Player Start is placed under SpawnPoint marker and a level goal handler prefab is placed under LevelGoal marker

Create Alternate Path#

We'll next create an alternate path branching off the main path so the player has another way of reaching the goal

Create a new node Layout Graph > Create Path

Connect the nodes together like below

Leave all the properties as default and hit Build

Select the Create Path node and inspect the properties

Change the Path Name from branch to alt. We will be referencing this path as alt in the future

You can specify the paths from which this path should start and end. The Start From Path parameter is set to main, referencing the main path we created in the previous section

The End On Path is left empty, so the end of this path doesn't connect back to anything. We'd like this path to connect back to the main path.

Set the End On Path parameter to main

PropertyValue
Min Path Size3
Max Path Size5
Path Namealt
Node Colororange
Start From Pathmain
End On Pathmain

This will make the alternate path (orange) connect back to the main path (green)

Keep hitting Build for different results

Assign a description to the node. Select the Create Path node and set the description property to Alternate Path

Create Treasure Room (Main)#

We'll add a treasure room connected to the main path

Add a new node Layout Graph > Create Path and set it up as follows:

PropertyValue
Min Path Size1
Max Path Size3
Path Nametreasure_main
Node Coloryellow
Start From Pathmain
End On Pathmain

Create Treasure Room (Alt)#

We'll add another treasure room connected to the alt path but keep the End On Path parameter empty so it doesn't connect back to anything:

Add a new node Layout Graph > Create Path and set it up as follows:

PropertyValue
Min Path Size1
Max Path Size1
Path Nametreasure_alt
Node Coloryellow
Start From Pathalt
End On Path

Create Key Room#

We'll create a room connected to the main path which will act as the key room. We'll later configure this room to have a key that opens up a lock in the main path. It will also have a NPC (key guardian) guarding the key

Add a new node Layout Graph > Create Path and set it up as follows:

PropertyValue
Min Path Size1
Max Path Size1
Path Namekey_room
Node Colorcyan
Start From Pathmain
End On Path

note

We've named this path key_room. It will be referenced later on when creating the key locks

Create Key-Lock (Main)#

We'll next create a key-lock system on the main path. Our key will go on the Key Room we created earlier (key_room path) and the lock will be somewhere in the main branch (main path)

Add a new node Layout Graph > Create Key Lock and set it up as follows:

PropertyValue
Key Branchkey_room
Lock Branchmain
Key Marker NameKeyRed
Lock Marker NameLockRed

Specify the Key Branch as key_room and Lock Branch as main

Set marker name for the key as KeyRed and lock as LockRed. Then in the theme file, you'd create marker nodes with these names and add your key and locked gate prefabs.

The sample theme already has these setup

Create Key-Lock (Treasure Main)#

We need a key-lock to guard the treasure room in the main branch

Add a new node Layout Graph > Create Key Lock and set it up as follows:

PropertyValue
Key Branchmain
Lock Branchtreasure_main
Key Marker NameKeyYellow
Lock Marker NameLockYellow

Set marker name for the key as KeyYellow and lock as LockYellow. Then in the theme file, you'd create marker nodes with these names and add your key and locked gate prefabs.

The sample theme already has these setup

Spawn Enemies (Main, Alt)#

We'll use the Spawn Items node to spawn enemies on the main and alt paths

Create a new node Layout Graph > Spawn Items and set it up as follows:

PropertyValue
Pathsmain, alt
Item TypeEnemy
Marker NameGrunt
Min Count1
Max Count5

This will spawn enemies in the nodes, gradually increasing the number of enemies based on the difficulty. The difficulty increases as we get closer to the goal. You can control this from the Spawn Method properties. Leave it to default for now

We've specified the marker name as Grunt and an appropriate marker node should be created in the theme file so we can spawn prefabs under it. The sample theme already has this marker

Spawn Bonus (Treasure Chests)#

Spawn treasure chests in your bonus rooms using the Spawn Items node

Create a new node Layout Graph > Spawn Items and set it up as follows:

PropertyValue
Pathstreasure_main, treasure_alt
Item TypeTreasure
Marker NameTreasure
Min Count1
Max Count1
Min Spawn Difficulty1

We've specified the marker name as Treasure and an appropriate marker node should be created in the theme file so we can spawn prefabs the treasure chest under it.

The Min Spawn Difficulty is set to 1. The first node in the branch will have a difficulty of 0 and the last node 1. Sometimes, the yellow branch may be 3 nodes long. Since we want the chest to occur only on the last node, we've set this value to 1

Spawn Key Guardian#

We'll add an NPC in the Key room guarding the key

Create a new node Layout Graph > Spawn Items and set it up as follows:

PropertyValue
Pathskey_room
Item TypeEnemy
Marker NameKeyGuardian
Min Count1
Max Count1

You'll need to create a marker named KeyGuardian in the theme file and place your NPC prefab under it. This marker doesn't exist in the sample theme and you'll need to create it yourself if you want to visualize it

Spawn Health Pack#

We'll use the Spawn Items node to spawn a few health pickups along the main and alt paths

This section also shows you how to use the Custom Item Type

Create a new node Layout Graph > Spawn Items and set it up as follows:

PropertyValue
Pathsmain, alt
Item TypeCustom
Marker NameHealthPickup
Min Count0
Max Count1
Spawn MethodRandom Range
Spawn Probability0.4
Custom Item Info > Preview TextH
Custom Item Info > Text ColorRed
Custom Item Info > Background ColorWhite

note

You'll need to create a marker named HealthPickup in your theme file and add your health pack actor. The sample theme doesn't contain this

Finalize Layout Graph#

After we are done designing the layout graph, we'll need to finalize it with the Finalize Graph node. This node does a few things:

  • Move the locks from the nodes on to the links
  • Create one way doors (so we don't go around locked doors)
  • Assign room types (Room, Corridor, Cave)

Create a new node Layout Graph > Finalize Graph and set it up as follows:

Leave all the properties to default

We are now ready to create a tilemap from this

Create Tilemap#

Create a new node Tilemap > Initialize Tilemap and set it up as follows:

You can control the thickness of the caves from the Cave Thickness parameter. Each node on the layout graph gets converted into rooms in the tilemap.

The parameter Tilemap Size Per Node controls how many tiles are used to generate a room from the node. Bump this number up if you want more space in your rooms

If you want a more uniform grid like look on your rooms, bring the Perturb Amount close to 0

When you select a node on the layout graph, the tiles that belong to the node light up. This is controlled by the Color Settings parameters

Layout Padding adds extra tiles around the dungeon layout. Set this value to 5 so we can apply some decorations outside the dungeon bounds

3D Viewport#

After you've initialized a tilemap, you now start to see a dungeon generated in the 3D viewport, representing by the tilemap.

The dungeon uses a default theme and the preview theme can be changed from the settings

Add Background Elevation#

We are going to create overlays and merge them with the original tilemap. Create the following two nodes:

  • Create a node Tilemap > Create Elevation
  • Create a node Tilemap > Merge Tilemaps

Link them up like below:

Update the properties:

Create Tilemap Elevation properties

PropertyValue
Noise Frequency0.1
Num Steps12
Min Height-10
Max Height10
Sea Level-1
Land ColorBrown (HexLinear 291A10FF)
Sea ColorBlue (HexLinear 003C66FF)

Create Tilemap Elevation Node Result

Merged Result

Dungeon Preview

We've specified the marker name as Elevation. If you place objects under the specified marker node in the theme editor, they will show up on these tiles at the given height.

note

The Min/Max height is logical and will be mulitplied by the dungeon config's Grid Size Y value. If the GridSize is (400, 200, 400) in the Dungeon actor's config and the tile height happens to be 2.5, the actual placement will be on 2.5 * 200 = 500 unreal units high

The sample theme file already contains a marker named 'Elevation' which shows the purple/blue tiles on the scene

There are two nodes attached with material overrides (purple and blue for land and sea tiles). There's a selector logic on the first node that gets selected if the tile is below sea level.

Add Grass Overlays#

We'll overlay some foliage on our dungeon using a noise parameter. Dungeon Architect always places the overlays in a way that they will not block the main path and the level will be playable. You can overlay rocks, trees and other blocking objects as well

Create a node Tilemap > Create Overlay

Create Overlay Node Connection

Create Overlay Node properties

PropertyValue
Marker NameGrass
Overlay Blocks TileFalse

Noise Settings:

PropertyValue
Noise Frequency0.15
Noise Max Value1.49
Noise Threshold0.5
Min Dist From Main Path1

Merge Config:

PropertyValue
Max Height1
Wall Override RuleKeep Wall Remove Overlay

Result of the Grass Overlay Node

Merged result

We've specified the marker name as Grass. You'll need to create this marker in the theme file and assign a mesh there. The sample theme already contains this

Dungeon Preview

Before / After Tilemap Result

Before / After Dungeon Result

Finalize Tilemap#

Finalize the tilemap to complete the grid flow graph

Create a node Tilemap > Finalize Tilemap

Finalize Tilemap node places all the items on to the tilemap (enemies, keys, bonus etc)

Optimize Tilemap#

When the tilemap based level is generated, there are many tiles that the player might never see, as they are far away from the dungeon layout

The Optimize Tilemap removes tiles that are away from the specified distance from the dungeon layout bounds

Optimize Tilemap Node Result

Create a node Tilemap > Optimize Tilemap

Connect it before the Finalize Tilemap node like below:

Set the Discard Distance from Layout value to 5

Optimize Tilemap Node properties

This will drop any tiles that are 5 tiles away from the nearest layout tile

Optimize Tilemap Before / After

Optimize Dungeon Preview Before / After