Auto-tiling in Tiled with Smart Tiles and Wang sets

Updated 2026-11-28 · Tiled MCP Pro 1.1.0

Edges are where tile maps go wrong: a wall needs the right corner, a lake the right shoreline piece on every side. Tiled MCP Pro has two engines that choose those pieces in code, so the AI only decides where each terrain goes. Both need the server in full mode.

Which engine to use

Your tilesetUseSetup
Has terrain (Wang) sets in Tiledplace_wang_terrainNone; it reads the Wang set.
No Wang sets, standard blob or 16-tile layoutSmart Tiles: define_autotile_rules + place_terrainMap neighbour patterns to tiles once; saved in the tileset.
No Wang sets, and you want Tiled's own terrain brush tooCreate a Wang set with add_terrain_set / set_terrain_tile, then place_wang_terrainAssign Wang IDs to tiles once.

Wang sets: place_wang_terrain

Pass a grid of terrain colors (1-based indices or color names, 0 or empty for "leave as is"), an origin, the layer, tileset and Wang set name. The tool computes the Wang ID of every cell from its neighbours, picks a matching tile, and with update_neighbors (the default) also re-picks the tiles around the edited area so the new terrain joins the old.

Call get_terrain_sets for "outdoor". Then on layer "Ground" use
place_wang_terrain with set "Terrains" to paint a 6x4 grass bank
(Grass) at x=34, y=12, and a 5x4 Dirt field next to it.
Lake beforebefore
Lake after place_wang_terrainafter
On Tiled's bundled orthogonal-outside example: a grass bank and a dirt field painted into the lake with place_wang_terrain. Shoreline tiles were chosen by the tool. Tileset: Michele "Buch" Bucelli, CC-BY 3.0.

The result lists how many tiles were placed and updated. Cells where the tileset has no exact tile for the needed combination come back as approximate (closest tile used) or unmatched, with coordinates, so the AI can fix them by hand or change the plan.

Making a Wang set with the AI

If you want Tiled's terrain brush to work for you as well, have the AI build the Wang set: add_terrain_set (type corner, edge or mixed), add_terrain_color for each terrain, then set_terrain_tile to give each tile its Wang ID. Let it call get_tileset_preview first so it assigns IDs by looking at the tiles, and check the result in Tiled's terrain editor.

Smart Tiles: bitmask rules

Smart Tiles work with any tileset, Wang sets or not. You (or the AI, after looking at the preview) define rules once:

The rules are stored as a custom property on the tileset, so they are saved with it and survive restarts. get_autotile_rules reads them back.

Look at get_tileset_preview for "walls". Define simple16 autotile
rules: terrain "wall" (symbol #) and "floor" (symbol .), mapping each
4-direction bitmask to the matching wall piece.

Bitmask cheat sheet

For each cell, add the weight of every neighbour that has the same terrain:

NeighbourNESWNESESWNW
Weight1248163264128

Painting with terrain names

place_terrain takes a grid of terrain names (empty string for no change). place_terrain_rect fills a rectangle. Both re-pick neighbouring tiles by default.

place_terrain_rect layer=Walls tileset=walls x=0 y=0 width=24 height=16 terrain=wall
place_terrain_rect layer=Walls tileset=walls x=1 y=1 width=22 height=14 terrain=floor

Two calls produce a walled room with correct corners; carving more rooms and corridors with floor updates the wall pieces around them.

Reading a map back as terrain

get_semantic_map (Smart Tiles) and get_wang_terrain_map (Wang sets) turn a layer back into terrain, so the model reasons about rooms and paths instead of tile IDs:

##########
#........#
#..~~~...#
#..~~~...#
####..####
   #..#

Limits and fixes

Get Tiled MCP Pro
$10 once on itch.io, free updates.

itch.io · $10

More guides