Loading...
Loading...
Build and script 2D tilemaps in Unity 6: the Grid + Tilemap components, the Tile Palette, tilemap colliders, rule tiles, and runtime SetTile/GetTile painting. Use when painting tile levels, adding a TilemapCollider2D, using rule or animated tiles, generating tilemaps from code, or when the user mentions Unity tilemap, tile palette, rule tile, or Grid.
npx skill4agent add gamedev-skills/awesome-gamedev-agent-skills unity-tilemap-2dGridTilemapPackage note: the core Tilemap (,Grid,Tilemap,Tile) is built in. Rule Tiles, Animated Tiles, and Tile Palette brushes live in the separate "2D Tilemap Extras" package (TilemapCollider2D) — install it via Package Manager before usingcom.unity.2d.tilemap.extras.RuleTile
GridTilemapGridTilemap*.assetlevel-designplatformerunity-physicsGridTilemapTilemapRendererTileTilemapCollider2DCompositeCollider2DRigidbody2DVector3IntSetTileGetTileSetTilesBlockGridTilemapRefreshAllTilesusing UnityEngine;
using UnityEngine.Tilemaps;
public class TilePainter : MonoBehaviour
{
[SerializeField] private Tilemap tilemap; // assign the target Tilemap
[SerializeField] private TileBase groundTile;
// World position -> cell, then place a tile.
public void PaintAt(Vector3 worldPos)
{
Vector3Int cell = tilemap.WorldToCell(worldPos);
tilemap.SetTile(cell, groundTile);
}
public bool IsSolid(Vector3 worldPos)
=> tilemap.GetTile(tilemap.WorldToCell(worldPos)) != null;
}SetTile// SetTilesBlock writes a whole BoundsInt in one call — use it for procedural rooms/floors.
public void FillFloor(Tilemap map, TileBase tile, int width, int height)
{
var bounds = new BoundsInt(0, 0, 0, width, height, 1);
var tiles = new TileBase[width * height];
for (int i = 0; i < tiles.Length; i++) tiles[i] = tile;
map.SetTilesBlock(bounds, tiles);
}tilemap.SetTile(cell, null); // null erases the tile at that cell
tilemap.RefreshTile(cell); // re-evaluate just this cell's rule/animated neighbors (cheap)
// RefreshAllTiles() re-evaluates the ENTIRE map — reserve it for full regenerations, not per-edit.RuleTilecom.unity.2d.tilemap.extrasCompositeCollider2DRigidbody2DSetTileGetTileVector3IntWorldToCellCellToWorldTilemapRendererRefreshTile(cell)RefreshAllTiles()https://docs.unity3d.com/Manual/tilemaps/work-with-tilemaps/tilemap-reference.htmlScriptReference/Tilemaps.Tilemaphttps://docs.unity3d.com/Packages/com.unity.2d.tilemap.extras@1.6/manual/index.htmllevel-designprocedural-genSetTilesBlockplatformerroguelike