Introduction to Tilemap in Unity Part 2

Scriptable Tiles, Scriptable Brushes, Using 2D Tilemap Extras

James Lafritz
Dev Genius

--

Unity’s Tilemap is very extendable.

Scriptable Tiles

I can create my own Tile types by using Scriptable Tiles. This allows me to do all kinds of things like create auto tiling feature to Animating Tiles.

Scriptable Brushes

I can create my own Brushes by using Scriptable Brushes. I can create circle fill brushes, line fill, or brushes that paint prefabs.

2D TilemapExtras

These things take a lot of time to implement and get right. Luckly for us is Unity already did the work for us. They have a Preview Package called 2D Tilemap Extras which comes loaded with useful Brushes and Tiles. The most useful are Line Brush, Random Brush, GameObject Brush, Animated Tile, and Rule Tile.

I just realized that at some Unity has made this a release package as of Unity Version 2020.1. If you are using an older Version of Unity you will have to use the preview package.

Installing

Installing this is just like installing in other Package from the Package Manager. If you are using a Unity 2019 or earlier you will have to make sure to turn on preview settings.

Using the Different Brushes

Utilizing the different Brushes can greatly speed up your work flow.

Creating An Animated Tile

Creating an Animated Tile Is just like creating any other asset using the Create Menu. After it has been created all I have to do is add the frames to the animation

Next I Create a Tile Palette for the waterfalls. Then I draw them on the Tilemap.

Now I have a nice animated effect.

I increased the animation speed to 30. It is important to note that I want the min and max to be the same for the waterfall as Unity picks a random number between the min and max values to play the animation at.

Rule Tile

Creating an Rule Tile is just like creating any other asset using the Create Menu. After it has been created all I have to do is add the rules to make it auto tile. The way rules work is once there is a match it will select that match and use that tile. I set the default tile for my tiles to be the inner fill, added them to my pallet and painted them in the scene, this is so once my rules are created I can verify that they draw as I intended.

For my platform I have 4 edges, 4 outer corners 2 inner corners and 2 end caps. This gives me a total of 12 rules needed. I have to do the 2 end caps and 2 inner corners first. Then I do the Outer Corners and lastly the 4 edges. One of my inner corners is a special case depending on where it belongs, I can take care of this by using the extend neighbor check box which allows me to add extra neighbors to check. So I actually have 13 rules. When a rule is matched I can output a single tile, a random selection of tiles, or an animated tile. I can also output a Game Object, I won’t be using this. I use the Sprite Editor to help determine which tiles to use.

There are 3 rule conditions that can be used for the neighbor of the rule tile, a blank means don’t care, red x means the neighbor is not same rule tile, and a green arrow means the neighbor is same rule tile. Using the extended neighbor will add another set of neighbors for it to check as soon as you check one neighbor.

--

--

Excited about changing my hobby into a new carer with GameDevHQ course.