- Do Mesh Colliders slow down performance simply by existing or only when they are colliding?
- Do they directly impact FPS or do they slow down the in-game physics?
A moving body near a meshcollider needs to check for collisions against potentially every triangular face of the mesh. So for a detailed or non-convex mesh, or lots of bodies, this can get expensive. And of course, if you have a meshcollider moving near another meshcollider, you pay this cost combinatorically.
These costs hit during the physics update step, as part of its collision resolution. The physics engine doesn't know where to position things for the next frame until it's worked out which objects need to bounce or stop due to these collisions. So in extreme cases, this can make the physics update process take longer and delay rendering of the next frame, impacting the game's frames per second rate.
If your frame runs extremely slow, past the maximum allowed timestep configured in the Time Manager then Unity will start dropping physics steps to try to keep things moving. Only if that happens will your physics slow down relative to realtime, otherwise Unity's decoupled fixed timestep will keep your physics moving consistently even if the rendered FPS drops.
When the meshcollider is not moving, the physics engine can put it to sleep, and only check it when another body comes close enough to potentially hit it, saving quite a lot of computation.
So the cost isn't fixed every frame, it will vary based on the complexity of the physics interactions that need to be checked & resolved in that frame.
To manage this cost, your best bets are:
- Favour simpler collider types for dynamic objects, or terrain colliders for environments
- Minimize the number of faces in meshes used for collision
When possible, make mesh colliders convex, or break them into convex pieces
(convex meshcolliders can use faster algorithms than an exhaustive face-by-face check, though the worst-case complexity still grows with the face count in the mesh)
- Avoid moving big mesh colliders — see if you can keep them static and move things relative to them to create a sense of motion for big environmental collision shapes like a boat/spaceship
A Mesh Collider will have to figure out the collisions for every single face of the whole mesh, Therefore It would take Longer (No significant difference most of the time) and would consume more Hardware Resources which would also slow down the performance.
Q -) Do they reduce performance simply by existing or Colliding ?
A -) No they don't reduce performance by just existing, The performance gets a hit when they are colliding.
Q -) Do they directly impact FPS or do they slow down the in-game physics?
A -) Essentially in a Mesh Collider. The more the triangles, The more the performance hit and So on. Most developers actually spend too much time trying to optimize uncritical parts of their projects and This sometimes leads to the poor optimization of the actual critical parts. However to only answer Your question, Yes mesh colliders do actually Impact Fps if they have a lot of faces.
Unity first uses Axis-Alligned Bounding Boxes (AABB) to check which colliders actually have a chance to collide. Checking two AABB's for intersection is a very cheap operation. Only then does Unity check if the collider-geometries also collide.
That means a mesh-collider only consumes CPU cycles when its bounding box intersects that of another collider. As long as nothing is near it, the collider type doesn't matter much for collision detection performance. Another operation which can cost lots of CPU cycles is rotating, because whenever you rotate an object the engine needs to recalculate the size of its bounding box. By the way, the Unity API exposes the bounding boxes of colliders.