Quick answer: Pick one Match mode (Corners and Sides is the standard), paint peering bits on every tile so the matcher can find a candidate for every neighbor combination, and use a 3×3 test pattern to verify transitions.
You set up a grass-to-dirt terrain in Godot 4 and paint a square of dirt. The edges look reasonable but the corners show grass tiles where dirt should be, or dirt fragments inside the grass area. The matcher is picking tiles that don’t fit because not enough candidates have the right peering bits.
How Peering Bits Work
Godot’s terrain system labels each cell position with peering bits — colored squares indicating which terrain occupies each edge or corner of that tile. When you paint, the matcher picks a tile whose peering bits match the neighbor configuration. If multiple tiles match, it picks randomly. If none match, it falls back to an arbitrary tile that is close.
The Fix
Step 1: Pick one Match mode per TerrainSet. Corners and Sides uses all 8 neighbors. Corners uses 4 diagonals. Sides uses 4 edges. Once set, every tile in the set must paint bits for that mode.
Step 2: Paint peering bits on every tile. Open the TileSet resource, go to the Terrains tab, select the terrain, and paint bits on each tile. A fully-interior grass tile gets all 8 bits green. A grass tile with a dirt top-left corner gets 7 bits green and 1 bit brown. Miss a tile and the matcher has fewer candidates.
Step 3: Ensure a tile exists for every combination you care about. If you want a 3-way junction (grass, dirt, water meeting), you need a tile with the right mix of peering colors. Missing combinations show as an arbitrary fallback.
Verifying
Use set_cells_terrain_connect from GDScript to paint programmatically and log the selected tile:
var cells = [Vector2i(0,0), Vector2i(1,0), Vector2i(0,1), Vector2i(1,1)]
$TileMap.set_cells_terrain_connect(0, cells, 0, 0)
for c in cells:
print(c, ": ", $TileMap.get_cell_atlas_coords(0, c))
If the printed coords match the tiles you expect, bits are correct. If not, open the TileSet and paint the missing bits.
“Terrain autotiling is just pattern matching. Give the matcher enough patterns and it works. Starve it and it picks the wrong tile every time.”
Related Issues
For tilemap collision issues, see Godot tilemap terrain autotile not connecting. For editor-time mismatches, see Godot tileset editor terrain rules not matching.
Paint a 3x3 test pattern with the terrain brush and cycle each corner. Any tile that looks wrong is a peering bit you missed.