Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Performance! OverlapCircle vs OverlapBox...

Discussion in 'Physics' started by Lazy_Sloth, Aug 25, 2020.

  1. Lazy_Sloth

    Lazy_Sloth

    Joined:
    Apr 3, 2018
    Posts:
    39
    Hello!

    I have to check a lot of collision by one of the above mentioned function and I want to do in the most performance efficient way.

    So, which one the "lighter" method?
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,321
    Circle/Circle testing is the most efficient. Detection of circles is quick because it's a simple radius check. Circle/Polygon is faster than Polygon/Polygon.
     
    Last edited: Aug 26, 2020
    Lazy_Sloth likes this.
  3. Lazy_Sloth

    Lazy_Sloth

    Joined:
    Apr 3, 2018
    Posts:
    39
    Thank you!

    So, the OverlapCircle is better than the OverlapBox. I check collision with OverlapCircle agains BoxCollider2D.
    Would be better to check again CircleCollider2D? Would it be significantly faster?

    UPDATE: I just started to visualise the collider by Gizmos.DrawCube/DrawSphere and I realized the DrawCube is 5-6 times faster to draw. I know the drawing is different from collider checking, but it looks faster to calculate a cube.. How is it possible? Maybe to calculate the OverlapBox is faster than OverlapCircle? Sounds un-logical, but why faster to draw a cube than a shpere? Sorry about it but it's so confusing to me :(
     
    Last edited: Aug 26, 2020
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,321
    Rendering has nothing whatsoever to do with physics so it's unclear why you're mixing concepts of physics detection with the rendering of gizmos and their respective performance.

    The sphere draw is probably slower because rather than drawing 12 lines, it draws many small edges to approximate the sphere.
     
  5. Lazy_Sloth

    Lazy_Sloth

    Joined:
    Apr 3, 2018
    Posts:
    39
    Yes, you're right! I don't know why I mix the two concept, I was confused by my "result", but the rendering is a full different thing and 4 line is faster to render than 12-16... Thanks for your patient ;)