【Godot】Setting Up Auto-Tiling with Terrains

Created: 2025-06-20Last updated: 2025-12-06

Automatically detect tile boundaries and place appropriate tiles. Enables efficient map creation

Overview

Tilemaps are essential for creating 2D game backgrounds. However, manually placing tiles one by one at boundaries—grass meeting dirt, cliff corners—is extremely tedious work. Godot 4 includes the "Terrains" feature (equivalent to Autotile in Godot 3) that intelligently places appropriate tiles automatically.

This article explains how to automate tedious tile placement using Godot 4's powerful Terrains feature.

What is the Terrains Feature?

The Terrains feature lets you assign terrain information (like "this is grass" or "this is dirt") and adjacent tile patterns (Peering Bits) to each tile in your tileset. Then, when you paint in the tilemap editor, it automatically selects and places the appropriate tiles.

While similar to Godot 3's "Autotile," Godot 4's Terrains is more powerful, capable of handling complex situations where multiple terrains meet.

Three Steps to Configure Terrains

The setup may look complex, but following these steps will guide you through. Let's try with two terrain types: Grass and Dirt.

Step 1: Create a Terrain Set in TileSet Editor

  1. Select the TileMap node, click the TileSet property in Inspector, and open the TileSet editor at the bottom of the screen.
  2. In the Terrains section of Inspector, click "Add element" to create a new Terrain Set.
  3. Set the Mode of your created Terrain Set according to your tileset type. Match Corners and Sides (3x3) works for most cases.

Step 2: Create Terrains

  1. Expand the created Terrain Set and click "Add element" twice in the Terrains property to create two Terrain slots.
  2. Name them "Grass" and "Dirt" with distinctive Color values. Your terrain definitions are now complete.

Step 3: Set Terrain Information on Each Tile (Peering Bits)

This is the most important step.

  1. Select "Paint" property in the TileSet editor.
  2. In the right-side Inspector, set Properties > Terrains > Terrain Set to 0 (the one you just created).
  3. Select the tile you want to configure (e.g., grass tile) from the TileSet panel.
  4. Use the Paint brush to paint terrain information onto the selected tile. Select "Grass" (0) in the Terrain property and paint which parts of the tile are grass.

Terrain Peering Bits Configuration
From Godot official documentation. The center 9 squares represent Peering Bits

Correctly setting the Peering Bits (the center 3x3 grid) is crucial. These define the rule "when should this tile be displayed based on surrounding tiles?"

  • Center square: This tile's own terrain (e.g., Grass)
  • Surrounding 8 squares: Adjacent tiles' terrains (e.g., Dirt, or empty space)

For example, for the top-right corner of a grass area, you'd set center, left, bottom-left, and bottom as "Grass," with the rest as "Dirt" or "empty." Apply this configuration to all boundary tile patterns (16-tile or 47-tile sets, etc.).

Painting with the Terrain Brush

Once configuration is complete, return to the TileMap editor and select the Terrains tab. You should see your configured terrains (Grass and Dirt) in the palette.

Simply select the terrain you want to paint and drag across the canvas. Godot automatically places appropriate boundary tiles following the Peering Bits rules. Level creation becomes intuitive—a far cry from manually selecting tiles one by one.

Summary

Setting up the Terrains feature takes some initial effort. However, once configured, your level design efficiency improves dramatically. The benefits are immeasurable, especially when creating large maps or frequently revising designs.

Start by trying the Terrains feature with just two simple terrain types and experience its convenience firsthand.