Dungeon Architect for Unity 1.20 Help

Design a Grid Flow Graph

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

Setup

Destroy the existing dungeon and clear out the Flow Asset that we assigned earlier

DungeonGridFlow game object properties

Create a new Grid Flow asset from either the Create menu or the Main Menu

Create Menu
Main Menu

Rename to something appropriate and double click the grid flow asset to open it in the editor

We won't be needing the scene view for some time. Dock the editor so we have more working area

Ut 04 20

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

Ut 04 menu l create grid
Ut 04 21

Connect this node to the Result node and hit build

Ut 04 22
Ut 04 11

This node creates an initial grid to work with

Ut 04 23

In this builder, you first design your level in an abstract layout graph like this and then move the final result to a tilemap

Create Main Path

We'll next create a main path within this grid. The main path has a spawn point and goal

Create a new node Layout Graph > Create Main Path

Ut 04 menu l create main path

Unlink the Create Grid node from the Result node (do this by right clicking on the node's orange border)

Ut 04 24

Link the nodes up like below and click Build

Ut 04 25

This node creates a main path in the grid. Keep clicking the build button for different result

Ut 04 26

Select the Create Main Path node and inspect the properties

Ut 04 27

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 Prehistoric theme, there's a marker already created with these names and a player controller is placed under SpawnPoint marker and a level goal handler prefab is placed under LevelGoal marker

Ut 04 28

Create Alternate Path

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

Create a new node Layout Graph > Create Path

Ut 04 menu l create path

Connect the nodes together like below

Ut 04 29

Leave all the properties as default and click build

Ut 04 30

Select the Create Path node and inspect the properties

Ut 04 31

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

Ut 04 32

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

Ut 04 33

Parameter

Value

Min Path Size

3

Max Path Size

3

Path Name

alt

Node Color

orange

Start From Path

main

End On Path

main

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

Ut 04 34

Keep clicking build for different results

Ut 04 35

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:

Ut 04 37
Ut 04 36

Parameter

Value

Min Path Size

1

Max Path Size

3

Path Name

treasure_main

Node Color

yellow

Start From Path

main

End On Path

main

Ut 04 38

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:

Ut 04 39
Ut 04 40

Parameter

Value

Min Path Size

1

Max Path Size

1

Path Name

treasure_alt

Node Color

yellow

Start From Path

alt

End On Path

Ut 04 41

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:

Ut 04 42
Ut 04 43

Parameter

Value

Min Path Size

1

Max Path Size

1

Path Name

key_room

Node Color

cyan

Start From Path

main

End On Path

Ut 04 44

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:

Ut 04 menu l create key lock
Ut 04 45
Ut 04 46

Paramter

Value

Key Branch

key_room

Lock Branch

main

Key Marker Name

KeyMain

Lock Marker Name

LockMain

Ut 04 47

Specify the Key Branch as key_room and Lock Branch as main

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

The prehistoric theme already has these setup

Ut 04 48

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:

Ut 04 49
Ut 04 50

Parameter

Value

Key Branch

main

Lock Branch

treasure_main

Key Marker Name

KeyTreasure

Lock Marker Name

LockTreasure

Ut 04 51

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

The prehistoric theme already has these setup

Ut 04 52

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:

Ut 04 menu l spawn items
Ut 04 53
Ut 04 54

Parameter

Value

Paths

main, alt

Item Type

Enemy

Marker Name

Grunt

Min Count

1

Max Count

5

Ut 04 55

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 pre-historic theme already has this marker

Ut 04 56

You can control the placement of items (in the tilemap) from the Placement Method property section. Leave it to default for now

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:

Ut 04 57
Ut 04 58

Parameter

Value

Paths

treasure_main, treasure_alt

Item Type

Bonus

Marker Name

Treasure

Min Count

1

Max Count

1

Min Spawn Difficulty

1

Ut 04 59

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 pre-historic theme already has this marker

Ut 04 60

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:

Ut 04 61
Ut 04 62

Parameter

Value

Paths

key_room

Item Type

Enemy

Marker Name

KeyGuardian

Min Count

1

Max Count

1

Ut 04 63

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 Prehistoric 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:

Ut 04 64
Ut 04 65

Parameter

Value

Paths

main, alt

Item Type

Custom

Marker Name

HealthPickup

Min Count

0

Max Count

1

Spawn Probability

0.5

Custom Item Info > Item Type

health_pickup

Custom Item Info > Text

Health

Custom Item Info > Text Color

[Red]

Custom Item Info > Background Color

[White]

Ut 04 66

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:

Ut 04 menu l finalize
Ut 04 67

Leave all the properties to default

Ut 04 68
Ut 04 69

We are now ready to create a tilemap from this

Initialize Tilemap

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

Ut 04 menu t initialize
Ut 04 70
Ut 04 71
Ut 04 72a

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

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

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

Wall Generation Method

Ut 04 72b

There are two ways of generating the walls, which depends on the asset you use for the dungeon.

  • Walls as Tiles: The walls will take up a full tile in the tilemap. Use this if your wall prefab are as thick as the size of a ground tile. In the image below, walls tiles are grey

    Ut 04 72d
  • Walls as Edges The walls do not take up any tiles and are aligned on the edges of a tile. Use this if your wall prefab is thin. In the image below, walls are red lines

    Ut 04 72c

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 Tilemap Elevations

  • Create a node Tilemap > Merge Tilemaps

Ut 04 menu t create elevation
Ut 04 menu t merge

Link them up like below:

Ut 04 73
Create Tilemap Elevation properties

Update the properties

Parameter

Value

Noise Frequency

0.1

Num Steps

8

Min Height

0.5

Max Height

3.5

Sea Level

-1

Create Tilemap Elevation Node Result

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

Add Tree Overlays

We'll overlay trees on our dungeon using a noise parameter. These overlays will be placed such that they will not block the main path

Create a node Tilemap > Create Tilemap Overlay

Ut 04 menu t create overlay
Create Tilemap Overlay Node Connection
Create Tilemap Overlay Node properties

Noise Settings

Parameter

Value

Noise Frequency

0.2

Noise Max Value

1.5

Noise Threshold

0.75

Min Dist From Main Path

1

Merge Config

Parameter

Value

Max Height

1

Result of the Create Tilemap Overlay Node
Merged result

Finalize Tilemap

Finalize the tilemap to complete the grid flow graph

Create a node Tilemap > Finalize Tilemap

Ut 04 menu t finalize
Ut 04 80
Ut 04 81

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

Build Dungeon

Assign this grid flow graph to your DungeonGridFlow game object and click Build Dungeon

Ut 04 82
Ut 04 83

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

Ut 04 84

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

Optimize Tilemap Node Result
Optimize Tilemap Before / After

Create a node Tilemap > Optimize Tilemap

Ut 04 menu t optimize

Connect it before the Finalize Tilemap node like below:

Ut 04 88
Optimize Tilemap Node properties

Rebuild the dungeon in the scene view

Optimize Tilemap Before / After
Last modified: 24 January 2024