- Home /
CircleCollider2D vs PolygonCollider2D: which collision solving is less expensive?
Say I have a gameobject with Rigidbody2D and X circle colliders. Other gameobject also has Rigidbody2D and PolygonCollider2D with 2X points. Which of two gameobjects is less expensive in terms of CPU usage when solving collisions?
Circle tests are always the most performant, no matter what. It's a simple distance between centers vs. the sum of their radii comparison
Let me please just repeat my question: Which of two gameobjects is less expensive?
@hexagonius I think the question is a bit more involved than just a comparison of individual colliders' performance.
It's multiple circles vs a single polygon. From the X vs 2X, I'm guessing they've got a polygon and are wanting to decide between
a) a single polygon collider,
and
b) circle colliders at each vertex and halfway along each edge.
On reflection - the X and 2X are the wrong way round for that. @madfatcat what is your actual use case?
Your case is very specific you could just monitor the difference in the profiler ?
Answer by hexagonius · Oct 18, 2019 at 10:26 AM
The fact that we do not know how the collision solving is implemented and we also do not know your X, we can't say anything about this. The other fact is that the question is odd. You can only solve a collision between two GameObjects, otherwise there is no collision to solve, so it's not possible to split the cost between the two.
What you could to is setup a solver scenario, duplicate this a couple of hundred times and see what the profiler spits out during the solving frame. Do the same with a change in object count. I wouldn't be surprised if factors like "on which side of a polygon collider does the collision occur" or "is it convex or concave" would also matter.
From my experience, questions like "which does cost more performance" can almost never be answered without profiling them, which is why I initially answered with the rule of thumb of circle collisions being the least expensive.
Your answer
Follow this Question
Related Questions
Problem with method Collider2D.isTouchingLayers() 4 Answers
Tilemap Collider 2D preventing objects from moving 2 Answers
Static Colliders in the 2D Engine in Unity 5 1 Answer
Physics2D.OverlapCircle dont detect triggers 3 Answers
Help needed making fake 3D collision in a beat em up style 2D project 1 Answer