How to use Rule Tile in Unity 2022

 
  1. Ensure that you have a 2D project (packages imported)

 

The Rule Tile is only available after you install the 2D Tilemap Extras package (that will be pretty useless without the 2D Tilemap Editor package). It is by default installed when you create a new Unity project using the 2D template.

 

2. Create a Rule Tile

 

Right click in the Project Tab and crate a Rule Tile Create -> 2D -> Tiles -> Rule Tile

If you select it in the inspector you will see some properties. First (1.) you need to select the Default sprite. Next you can specify the other sprites that will define your rule tile (2.)

I will be using Wall Tileset: corner, 3-way, 2 types of side wall and an end tile (not shown here).

I have used a Side Left-Right as a default tile and the other ones for use as Rules.

 
 

3. Defining rules

 

Now we can define basic rules.

Here I have a Corner tile that connects Bottom with Right side.

I can click in the 3x3 grid on any field (but the center field) to select:

  • Empty field = DOESN’T matter

  • Green Arrow = another rule tile MUST be in this direction for this rule to be applied

  • Red X = another Rule tile CAN’T be in this direction for this rule to be applied

We can define the Extra Neighbor tiles to have a 5x5 grid if our rules are very complex

After defining the basic rules we can use the MIDDLE field to specify additional rules:

  • Fixed = set by default - just means that this rule will be used as is

  • Rotated (an arrow) = this rule will be rotated by 90 degrees (max 4 times) if it doesn’t fit in the original rotation. This will allows us to define a single corner rule.

  • MirrorX / Y / XY = The same as Rotated but instead of the rule being rotated it will be mirrored.

You can read more about those extra rules here docs.unity3d.com/Packages/com.unity.2d.tilemap.extras@1.6/manual/RuleTile.html

If you have all the rules set you can just drag the Rule Tile into your TilePaletter and when you paint the tile near other of the same type the rules should be applied helping you paint a continuous wall without you having to manually paint other tile types!

 
 
 

Are you enjoying this article so far?

Do you want to learn more about coding in Unity? Check out my video course:

 

I hope that you have enjoyed this blog post!

You can also support me through Patreon:

 

Thanks for reading!

Peter

Next
Next

How to add Bullet Holes and Stickers in Unity (URP)