Using Rule Tiles
20 Mins
Rule Tiles are scriptable tiles written in C#, which are smart enough to use the appropriate adjacent tiles, and handle tile animation, boundaries, and collisions on the fly.
In this tutorial, you will set rules on a tile and experiment with the properties and settings of a Rule Tile.
Topics we'll cover
Recommended Unity Versions
2017.2 and Above
Using Rule Tiles
What are Rule Tiles?
Rule Tiles are scriptable tiles written in C#, which helps define the behavior of the tiles in a Tile Palette. This has many beneficial uses: for instance, it allows you to paint a scene with the Rule Tile and have it be smart enough to use the appropriate adjacent tiles. The Rule Tile can also be set to handle animating tiles, boundaries, and collisions on the fly, which helps speed up the creation process.

Creating a Rule Tile
To create a Rule Tile:
  • Right-click in the content window and select Create > Rule Tile. (Figure 01)
  • Select the new Rule Tile you created to see the properties in the Inspector. (Figure 02)
Properties include:
  • Default Sprite: It doesn’t matter what you set this to, though it’s best to set it to one of the tiles that the RuleTile will affect.
  • Default Collider: This specifies the tiles’ physics interactions.
  • Tiling Rules: This is where you can add as many rules as there are tiles in the tile set. If there’s a tile image for which you don’t wish to create a rule, simply exclude it from the rules.

Adding Rule Tiles
  • Add the tiles you need to the Tiling Rules list. (Figure 03)
Each tile you add has additional properties:
  • Rule: You can select from Fixed, Rotated, Mirrored X, or Mirrored Y. This affects the orientation of the tile.
  • Collider: Change the Collider for a specific tile. This will override the default Collider.
  • Output: This determines how the tile is placed into the Scene. You can select from Single, Random, or Animation. Single will use the selected tile. Random will choose between a defined set of tiles. Animations will play an animation of specified tiles.
  • 3x3 Grid: When clicked, this will place an arrow. Click again and it turns to an x. Click once more and it clears the grid space. An arrow signifies that the tile is continuing from the direction the arrow is pointing. An x means the tile stops or has an edge at this point.
  • Tile Selection: This allows you to select a specific tile.
Take some time and set each property to see how it affects a tile.

Adding Animation to a Rule Tile
Select the Animation output. You will have an additional collection of tiles to set for that specific Rule Tile. (Figure 04)
There are two additional settings you should be aware of:
Speed: This determines the animation play speed.
  1. Select your Rule Tile that’s set to output Animation.
  2. Double the speed by changing the 1 to a 2.
Size: This is how many tiles exists in the sprite sheet. We need to set the tiles in the correct order to play them in the right sequence.
  1. Select your Rule Tile that’s set to output Animation.
  2. Set the Size to 5, or how many tiles that belong in the animation.
  3. Drag and drop your tiles into the rows, or click the circle asset browse icon to the right.
  4. Make sure you set the Sprites in the right order, with the top being the start of the animation and the bottom being the end of the animation.

Painting with the Rule Tile
Once the Rule Tile is set up:
  1. Drag the Rule Tile into your Tile Palette.
  2. Select the Brush and begin painting within your Scene.