Introduction to Tilemap in Unity

In this article, we will go over how to use Tilemap to create a 2D level. Tilemap allows you to paint from a made Sprite Palette onto a Tilemap grid.

The first thing we will need to do is create a Tilemap for the scene. To do that, you select Tilemap under 2D from the Create menu. There are a few different types of Tilemaps, but we are going to use the Rectangular type for this.

Next, we need to set up a Texture to be useable for the Tilemap. To do that, select the Texture from the Project window, then change the Texture Type from Default to Sprite (2D and UI) in the Inspector window. Depending on the Texture, you may need to change the Sprite Mode. If the Texture is supposed to be one solid piece, you use Single, or in this Texture, multiple pieces you use Multiple. The Pixels Per Unit determines the size of the sprite created from the Texture. For best results, you want to set the value to the width in pixels of the image or piece of the image in sprites set to Multiple. Once everything is set, click Apply to change the Texture to a sprite.

Next, divide the sprite into multiple sprites; click the Sprite Editor button to open the Sprite Editor window. Click Slice and set up the settings to your image size. In this case, the sprite should be divided into a 128x128 cell size grid. Once you have the settings in, click Slice and then Apply. If you go to the Texture in the Project window, you can see all its divided sprites.

To start adding tiles to the Tilemap, we need to use the Tile Palette. The Tile Palette window is under 2D in the Window dropdown. Next, we need a Palette for the tiles. Click Create New Palette to create one. After the Palette has been made, drag the Texture into the window to create the Tile Assets. You can add multiple Textures to a single Palette or create one for each Texture.

The Tile Palette has several tools you can use to create the Tilemap.

Select: Use the Select Tool to select a Tile on the Active Tilemap or hold and drag over multiple Tiles to choose more at once.

Move: Use the Move Tool to move the Select Tool’s Tile selection. Hold and drag selected Tiles to another position on the Tilemap.

Paintbrush: Use the Paintbrush Tool to select a Tile in the Tilemap Palette, or hold and drag over multiple Tiles to choose more at once. Then click on the Tilemap in the Scene to begin painting with your selected Tiles.

Box Fill: Hold and drag the Box Fill Tool over the Tilemap to draw a rectangular shape that fills with the selected Tile(s.)

Picker: Use the Picker Tool to pick a Tile from the Tilemap; hold and drag over multiple Tiles to select more at once. The active tool switches to the Paintbrush Tool once a selection is made with the chosen Tiles as the brush.

Eraser: Use the Eraser Tool to erase Tiles from the Tilemap by selecting them while the tool is enabled.

Flood Fill: The Flood Fill Tool is used to fill a contiguous area of empty cells or identical Tiles with the selected Tile.

You can use multiple Tilemaps to create a layered scene, allowing you to create a background and a foreground by changing the Sorting Layer of the Tilemap.

The following article will look at the 2D Tilemap Extras feature of Animated Tiles to create a waterfall.

Unity Developer, Software Engineer, Game Developer