Pattern Matcher - Basics


Capture patterns in your dungeon layout and add or remove markers around this pattern. This is a powerful system for decorating your themes, as you are no longer restricted to a single tile level decoration and can decorate across multiple tiles using your own patterns

Pattern Matcher

Create a Pattern Matcher asset#

Create a new asset by right-clicking on the project window: Create > Dungeon Architect > Theme Engine > Pattern Matcher

Pattern Matcher

Double-click the asset to open up the Pattern Matcher editor

Pattern Matcher

Pattern Matcher

Create your first Pattern#

Create a new Pattern#

Start by adding a new pattern by clicking the Add button in the Patterns panel

Pattern Matcher

You can have multiple patterns, and they run in sequence one after the other

Pattern Matcher

Pattern Rules#

A pattern is formed by assembling various pattern rules together (think of them as blocks arranged in a certain way)

Pattern Matcher

Right click on an emtpy space and select Add new Rule

Pattern Matcher

This will create a new rule

Pattern Matcher

You can click and drag the rule to another location

Pattern Matcher

Pattern Matcher

Pattern Matcher

Move the rule to an tile position like shown below and select it

Pattern Matcher

Pattern Rule Graph#

Each Pattern rule block has a rule graph. Here you define what needs to be present (or not present) at this location for the pattern to match

The Should Select? node takes in the result of your condition (boolean).

Create a graph like this:

The text in the rule block will update to reflect the rule graph condition

If the pattern is matched (i.e. the condition of every rule block succeeds), then the On Selected node will fire on all the rule blocks. Use this node to either emit or remove markers at this block's location (more on this shortly)

Create a new rule node next to it as shown below. Place a similar constraint to make sure a ground marker exists in this location

Our pattern will now match two adjacent ground blocks, and we can place a 1x2 Ground tile here

Whenever this pattern matches, it would fire off the On Pattern Selected node

Select any one of the two rule block and add a Emit Marker node with the name Ground1x2 (later, you'll need to adjust the mesh's offset transform accordingly depending on which block you chose)

It should look like this:

So, when the dungeon is created in the scene, this would create a marker named Ground1x2 on all the places where the pattern matched. We'll need to switch back to the Theme Graph app mode, so we can add our art asset under the Ground1x2 marker

Setup Theme#

Let's clone a scene from the launchpad and set up our pattern matcher asset in it

Navigate to Main Menu: Dungeon Architect > Launch Pad

Clone a Candy Grid builder theme. Navigate to the Samples, scroll down to the Grid category and clone the Demo scene as shown below

Select the dungeon game object and assign our pattern matcher asset to it

Add Marker Node#

Open up the theme file linked to this dungeon and create a new marker node named Ground1x2

Add this prefab under the Ground1x2 marker node: /Game/Geometry/Meshes/1M_Cube_Chamfer

We want to scale the cube along X axis by 2 units nudge it to the right (since this is a wide tile and is spawned on one of the tile)

Select the Cube mesh node in the theme graph and set the following transform:

The result looks like this:

It has inserted our wide tiles, however there are overlaps.

Avoid Overlaps#

Since we are emitting a marker in the left rule block (blue), the system already knows that there might be something spawned at that location, and it will try not to overlap it when searching for this pattern through the scene.

However, it does now know that the art asset you plan to insert here would take up 2 tiles and the block on the right (pink) would also be occupied. To let the system know this, select the block on the right (pink) and check Hint Will Insert Asset Here

The tiles no longer overlap

Remove Markers#

Since we are inserting a 2-wide ground tile, we don't need the Ground marker in its place as it's redundant.

Select each of the two rule blocks and add a Remove Marker node with the value Ground like shown below


Just for consistency, let's update the Candy theme's ground tile to have the same art asset. We've removed the default ground mesh node and replaced it with a new mesh node that has the same chamfered gray cube (scaled to 4x1x4 since it takes up a single tile)


Same Height Constraint#

We have a problem in some locations. We don't want ground tiles in adjacent locations to be merged if they are in different heights

To fix this, select the pattern and have a look at the details panel

Add an entry to the Same Height Markers list named Ground. This will match the pattern where all the entries in this list are in the same height


Change the layer's probability field to a value between 0 and 1 (i.e. 0% to 100%). Setting this to 0.5 would insert our wide tiles 50% of the time

Before (with 100% probability):

After (with 50% probability):

Extend further#

Another pattern was added for 2x2 tiles with a probability of 0.5 (and moved up to the first entry)


You can do a lot more with the system. More examples will be added to this section soon