Search Unity

Capsule vs Box Colliders

Discussion in 'Editor & General Support' started by freshcut, Nov 11, 2009.

Thread Status:
Not open for further replies.
  1. freshcut

    freshcut

    Joined:
    Nov 17, 2008
    Posts:
    71
    Quite simply, which one is more expensive?
    I have a scene with about 10000 static colliders, they can approximately be boxes or capsules so its not too much of an issue which one I choose. Though I haven't thoroughly profiled it, comparing the two, my eyes seemed to tell me that capsule colliders were performing quicker but logically i think boxes should be quicker.

    Anyone know for definite which it is?


    Many thanks
     
  2. freshcut

    freshcut

    Joined:
    Nov 17, 2008
    Posts:
    71
    Well I decided to post some results from some testing.
    All tests were done on an intel core2duo 3ghz imac with no rendering, just physics.

    Static colliders seem to have such a minimal impact on performance, Upto 60,000 and beyond of all different colliders were causing no noticable effect on the frame time (<3ms)

    So I tried testing dynamic colliders instead, much more challenging.

    Remember this is just physics, your renderer would bottleneck way before reaching 2500 individual objects.

    Dynamic Tests:
    500 Colliders
    Capsule 2.1ms
    Box 2.6ms
    Sphere 2ms

    1000 Colliders
    Capsule 5.6ms
    Box 5.8ms
    Sphere 2.9ms

    1500 Colliders
    Capsule 16.1ms
    Box 20.5ms
    Sphere 4.8ms

    2500 Colliders
    Capsule 453-481ms
    Box 490-520ms
    Sphere 190-233ms

    So there you have it, across the board capsule actually beats box but not by a huge amount, and sphere obviously kicks everyones ass.
     
  3. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    Buried in the dust and no reply. Wow, this is really important stuff.
     
  4. spacefrog

    spacefrog

    Joined:
    Jun 14, 2009
    Posts:
    734
    yep - good info...

    sounds quite reasonable

    * sphere collider -> 1 Vector
    * capsule collider -> 2 sphere colliders + their distance vector
    * Box collider -> no clue how it's done ;-)
     
  5. AndyMartin458

    AndyMartin458

    Joined:
    Jul 15, 2012
    Posts:
    59
    Is this still true? Wow, what awesome info. I've had it all wrong and thought Box was the most efficient.
     
  6. fzd

    fzd

    Joined:
    Jan 30, 2013
    Posts:
    41
    I just tested this in Unity 5 RC2 on an old android Galaxy Note

    Test was 300 cubes in a blender (pictured) with either box, sphere or capsule colliders, with discrete collisions.

    Sphere: 11-12 FPS
    Capsule: 5-8 FPS
    Box: 2 FPS

    So box is really expensive

    Nice physics upgrade in Unity 5 though :)
     

    Attached Files:

  7. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    Interesting read. :cool:
     
  8. ArtOfWarfare

    ArtOfWarfare

    Joined:
    Sep 28, 2013
    Posts:
    23
    People who would expect the boxes to be faster aren't considering the possibility that the boxes are rotated, I imagine.

    I'm curious - is it faster if all of the boxes have fixed rotation, or does Unity not recognize that / have some way of being told that so it optimizes accordingly?

    I guess I'm just being silly. Premature optimization is the root of all evil, and it's easy enough to swap between the different colliders later on.
     
  9. Archie747

    Archie747

    Joined:
    Jan 7, 2015
    Posts:
    25
    wow this is what im looking for
    i plan to change all my chars from box collider to capsule, but afraid of the impact on performance
    turn out that capsule is better than box :D

    thanks for trying this @freshcut!
     
    Last edited: Jan 4, 2016
    unity7611 likes this.
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Guys, please. Just stop.

    You will find much greater performance hits from the actual physics and collisions. If things aren't touching, you can have far more. If some things are sleeping, you can have far more. Your fixed update rate affects performance, and layers are important for performance. It's not just about which collider might be a tiny bit quicker.

    While choosing a collider is important, bigger gains are obtained from what you do with them.
     
    Ostermalm likes this.
  11. Erikoinen

    Erikoinen

    Joined:
    Nov 10, 2014
    Posts:
    68
    Started wondering, too. Thanks for the tests!
     
  12. aorata

    aorata

    Joined:
    Feb 10, 2012
    Posts:
    28
    @hippocoder

    But that doesn't mean he isn't right. I have 500 + colliders on my scene, and since its a 2.5D side scroller, a lot of collisions are happening to tell the objects to do different things depending on where they are relative to the camera. So this info is really useful. Any little inch you can get when you deploy for mobile, is important.

    Unless I'm missing something.
     
  13. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    well, yes. But any primitive collider, you'll be finding that if its playable or not comes down to layers and what you're doing with them... if its mesh collider then it's a different story, those things are quite slow
     
  14. DarthDisembowel

    DarthDisembowel

    Joined:
    Jun 11, 2014
    Posts:
    54
    It is still useful fundamental information, no need to shoot the posters down for it.

    That said, hippocoder does have a point. Also, capsules might be more efficient, but generally take much longer to stabilize as they will tend to roll, whereas a box will stop moving once the bounce has settled and go to sleep. Physics might be cheaper but they will calculate for a longer time in many cases.
     
  15. cstlmode

    cstlmode

    Joined:
    Dec 2, 2014
    Posts:
    88
    Great and important read , thanx for it
    is there a way to find similar data on 2D colliders ?
     
    FreeFly90 likes this.
  16. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
  17. alkekapito

    alkekapito

    Joined:
    Nov 2, 2014
    Posts:
    2
    thinks for the information...
     
  18. meng33455432

    meng33455432

    Joined:
    Jul 25, 2017
    Posts:
    1
  19. yelaex

    yelaex

    Joined:
    Mar 25, 2019
    Posts:
    2
    Really nice test, thank you
     
  20. smhl

    smhl

    Joined:
    Mar 15, 2020
    Posts:
    2
    How do you test that?
    maybe you used profiler, but I want to know how can I test it again?
     
  21. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Steps to success:

    1. First and foremost, STOP necro-posting to 12-year-old threads. Start your own post, it's FREE.

    2. When you post you OWN NEW POST, keep this in mind:

    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    How to understand compiler and other errors and even fix them yourself:

    https://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    Necroposting:
     
  22. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Necro is valid and allowed on these forums. If we didn't allow it, threads would auto-lock and it has been discussed. The reason is a lot of data doesn't go stale. Some does, some is ongoing and should be revived. There's no hard rule.

    Given Unity can take years to finish a feature, it's not hard to see why.

    Agree with the rest.

    The last post on this was 2 years previously, not 12 :D
     
Thread Status:
Not open for further replies.