is it better to make one collider for a large landmass made of many tiles, or make each of the tiles have their own colliders?

I am making a 2D platformer, and in building the levels, i need to know what has a lesser effect on the engine, to have the many smaller colliders for each tiles, or really big ones for each land i create with smaller tiles. Thank you!

The short answer

Less colliders means Unity has to do less checks each physics update to check for collisions. So less equals better. However, some colliders are more demanding than others: a sphere/circle collider is really fast, a mesh collider is slowish. So in some cases it is better to have more sphere colliders instead of a few mesh colliders. It is for this reason compound colliders are used instead of mesh colliders for a character (well, in this case there’s a also a trade-off in precision of the collision). In other words: simple equals better. The most efficient collision systems is one that uses as few and simple colliders as possible. The size of the collider really does not matter: the math is still the same.

A bit more

If you have a large landmass consisting of different tiles, my first reflex is to think of compound colliders: use small colliders for the tiles that are isolated, and try to encapsulate the landmass in as few and simple colliders as possible. I would avoid mesh colliders unless the shape of your landmass is really complex (but you said it is tile-based so I’m guessing that is not the case).

What’s also important is what every tile needs to do. It might be useful to have a collider on a tile for different reasons: to detect if the player walks on the tile to make it explode for instance!

That said, game developers are overly obsessed with making everything efficient. My advice is to start with something clean and simple that works and if you notice collision is a bottleneck, or you want to optimise before release: revise your colliders. If not: go with whatever you really understand and feels right.

Hope that helps,

Cheers,

Sam

The size of the collider really does not matter: the math is still the same

Not true, it’s quite the opposite, - the physics is done in two stages: Broad phase (rough, inexpensive), Narrow Phase (expensive)

Broad Phase:

first of all, colliders are gathered into distinct groups, based on their location in the world. Colliders from separate groups are never checked for collisions between eachother, since we know they are far away.

Afterwards, for those in the same group, we approximated each such collider as a sphere collider (simplest to compute), and checks for intersection with sphere-approximations with the neighbors in its group.

This excludes even more candidates.

Narrow Phase:

Afterwards, entities in the same groups whose spheres intersect have to perform a full-blown triangle-to-triangle check, to detect intersection.

So, if your colliders are huge to begin with, they will end up in multiple groups at once.
Not only that, but these huge colliders will also survive the sphere-approximation check, and will have to check all of their faces against all faces of of colliders in groups.

If you have a massive land, it’s always better to split its collider into chunks.

In general follow the advice of SamAgten:

So in some cases it is better to have more sphere colliders instead of a few mesh colliders.

it’s always better to have sphere colliders instead of mesh colliders, but of course, don’t overdo it.

If your mesh collider consists of 200 triangles, 10 sphere colliders will definitelly be a gain in performance - but only if there are elements nearby with which to check for collisions (rigidbodies).

If there are no rigidbodies nearby, then as long as colliders are stationary, you shouldn’t see any gain.

Cheapest to expensive:

  1. Sphere Collider
  2. AABB
  3. Capsule Collider
  4. Box Collider
  5. Mesh Collider