To enable collision detection for tilesA simple class that allows a sprite to be rendered on a Tilemap. More info
See in Glossary, add a Tilemap Collider 2D component to the tilemap.
The Tilemap Collider 2D component automatically generates collider shapes for each tile in the tilemap, so that GameObjects with a Collider2D component collide with the tiles.
You can choose which tiles to enable collision for.
To add the component to a tilemap, follow these steps:
The Scene view displays the collider shapes as green outlines over the tilemap.
To make another GameObject collide with the tiles, refer to Collider 2D.
Follow these steps:
To change the shape that a tile uses to register a collision, use the Custom Physics Shape window in the Sprite Editor.
For more information about editing the shape, refer to Create collision shapes for a sprite.
To improve the performance of a tilemap with many collider shapes, add a Composite Collider 2D component. Unity merges the collider shapes of neighboring tiles together, which reduces how much Unity needs to calculate during a physics update.
Follow these steps:
For more information, refer to Composite Collider 2D component reference.
To further configure performance and collider behavior, use the TilemapCollider2D API.
By default, when you add or remove tiles, the Tilemap Collider 2D updates shapes during LateUpdate and batches multiple changes together for performance. To force immediate updates, follow these steps:
Tilemaps.TilemapCollider2D.ProcessTilemapChanges to process changes immediately.Tilemaps.TilemapCollider2D-hasTilemapChanges to determine if processing is required.For more information, refer to the TilemapCollider2D API.