The Tilemap ColliderAn invisible shape that is used to handle physical collisions for an object. A collider doesn’t need to be exactly the same shape as the object’s mesh - a rough approximation is often more efficient and indistinguishable in gameplay. More info
See in Glossary 2D component generates collider shapes for tilesA simple class that allows a sprite to be rendered on a Tilemap. More info
See in Glossary on a TilemapA GameObject that allows you to quickly create 2D levels using tiles and a grid overlay. More info
See in Glossary component on the same GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary. When you add or remove tiles on the Tilemap component, the Tilemap Collider 2D updates the collider shapes during LateUpdate
. It batches multiple tile changes together to minimize the impact on performance.
The collider shapes generated for each tile in the tilemap depend on the Collider Type set in the tile’s properties. For more information on how this component’s shape generation behavior corresponds to the Collider Types, refer to Tile asset reference.
You can use the Tilemap Collider 2D component together with the Composite Collider 2D component. When you add both components to the same tilemap, Unity composites the collider shapes of neighboring tiles together. This smoothens the corners and edges between collider shapes in neighboring tiles.
Using both components together reduces the number of individual collider shapes involved in a physics update, which reduces the amount of calculations required, and minimizes the impact on performance.
If you require immediate changes to happen to the collider, use Tilemaps.TilemapCollider2D.ProcessTilemapChanges to process them immediately. You can use Tilemaps.TilemapCollider2D-hasTilemapChanges to check if any processing is required.