Intro to Tilemaps in Unity 2021
The Tilemap component is a system which stores and handles Tile Assets for creating 2D levels. It transfers the…
What are Tilemaps?
Per Unity’s documentation:
“The Tilemap component is a system which stores and handles Tile Assets for creating 2D levels.
It transfers the required information from the Tiles placed on it to other related components such as the Tilemap Renderer and the Tilemap Collider 2D.
When you create a Tilemap, the Grid component is automatically parented to the Tilemap and acts as a guide when you lay out Tiles onto the Tilemap.
To create, modify, and pick the Tiles for painting onto a Tilemap, use the Tile Palette (menu: Window > 2D > Tile Palette) and its tools.”
Essentially, tilemaps are “maps” made of “tiles”. Easy, right?
They are one of the oldest tools for level designs in game development.
Experimenting with Tilemaps in Unity
Setup a new game in Unity 2021 using the built-in render pipeline, 2D core.
Right click in the Hierarchy window, then select 2D Object > Tilemap > Rectangular.
This will create a Grid game object with a Tilemap child game object.
The Tile Palette
The Tile Palette window is akin to a painter’s palette.
Where a painter would have various colored paints to dip his brush in, we have a selection of tiles that we can use in our scene.
For more information on Tile Palettes, see Unity’s documentation:
Create a Tilemap Palette
Creating a new Tilemap Palette is straight-forward.
In the Tilemap palette window, select the drop down shown and click “Create New Palette”.
Save it somewhere appropriate in your project’s Asset folder.
Next, take the texture you wish to use and modify it’s import settings to a Sprite in “Multiple” mode.
Now we’ll need to slice this image up according to the sprite creator’s original intent or our own intent if we are feeling clever.
The process is simple.
Simply click the “Slice” dropdown in the Sprite Editor, set it as a “Grid by Cell Size” and enter the desired dimensions for each tile.
We can see that our original tilemap sprite now has a bunch of children sprites for us to use as individual tiles.
Now that we know our tilemap size, let’s set the tilemap sprite’s Pixels Per Unity to match (128 in my case).
Now we can simply drag our sliced Ground sprite into the Tile Palette window (with Ground Palette selected).
This will give us an opportunity to choose where we would like to save our tile sprites.
Once that is done, we can see the individual tiles now display in our Tile Palette window.
Now we can select the paint brush in the Tile Palette window, select a tile, and then draw it onto our Scene view.
And that’s it, you’re ready to start laying out your killer platformer!