Adding Colliders to Tilemaps in Unity

Jon Jenkins
2 min readAug 13, 2021

--

Adding a collider to your Unity tile map is extremely easy and can be done in a couple of steps. This short article will demonstrate the process.

First add a tilemapcollider2d component to your tilemap with the add component button in the inspector. You can see what this does below:

What has happened is that every tile on the tilemap receives its own collider. It would be better if we had one collider that was a composite of all the tiles in the tilemap. This can be done by adding a compositecollider2d component to your tilemap like so:

Once you add the composite collider component, Unity will also add a rigidbody2d component, which depends on the composite collider. Change the rigidbody2d’s body type to static and then on the tilemap collider 2d component check the box next to used by composite. This can be seen above. What happens is that a collider will be created, which is essentially a composite of all the little colliders on each tile.

To demonstrate that our collider is working, I have added a square to the scene and given it a rigidbody2d and a collider2d so that it will fall to and collide with the platform below:

That’s all it takes to get a basic collider set up on your tilemap.

--

--

Jon Jenkins
Jon Jenkins

Written by Jon Jenkins

A Unity Developer, interested in all things Unity.

No responses yet