- Home /
Question regarding mesh collider vs primitives
Am I correct in thinking that mesh colliders are inherently less efficient than primitives by nature? Specifically if I took a box and placed a box collider on it would it be faster at resolving collisions than making a Mesh collider for the box even though the mesh collider is of course a box shape.
It appears it would be faster because the box collider does a distance bounds check and basically is alot faster because it gets to make assumptions because it knows its dealing with a box (AKA the width, height and depth are all equal)
I'm asking because i'd like to include a triangle in my game to allow people to edit with, the thing is a triangle isn't really a combination of any other shape or shapes.
Now its only 6 vertices so i'm not sure it matters even if i had several thousand floating around but it might, I know the fact that it is only 6 vertices helps it as a mesh even if it's not as fast as a box but i'd like some input from someone with more knowledge.
is a box or sphere collider faster than a box or sphere mesh collider and is there an easy way to deal with triangles using primitives or should i just use a mesh or what?
you've completely hit the nail on the head -- basically you DONT USE mesh colliders, ever, in video games. maybe for ground surfaces that are not flat.
this is exactly what it means to "make video games"
this question comes up all the time .. eg 5 $$anonymous$$s ago :)
http://answers.unity3d.com/questions/339406/how-to-approach-making-a-large-city-map.html
"yes, montray is right. You have to carefully create all the colliders -- that means box colliders and sphere colliders -- for a video game. It's how they are built!
$$anonymous$$esh colliders are rarely used for anything - "the ground" (if it's not flat) is about the only exception really.
typically your art department will give you an amazing city or whatever, and then the poor engineers spend weeks carefully making beautiful colliders that reasonably work with it, efficiently"
Answer by Owen-Reynolds · Oct 29, 2012 at 02:35 PM
Could just make a quick script to randomly spawn 1000 falling objects, swapping between box colliders and your triangle mesh ones.
But, some of the theory: the game engine does very fast, crude collision tests before even looking at the exact shape of your collider. Something like an Oct-tree groups the map into general areas, and skips collision testing for objects in different areas. This is why the frame-rate drops when you pile more objects together.
Objects have an axis-aligned bounding box (a big box with rotation 0,0,0, covering everything.) It's very fast to check "if your left side is past my right side" to rule out collisions.
When you finally get to the "real" collision test, sure, official boxes are probably faster. It might run only 6 checks for a Box collider, whereas 8 checks (1 per tri) on your 3D triangle mesh collider. Box colliders might "know" that checking the skinniest axis first will rule things out faster.
from the sounds of it a mesh collider triangle is still faster then than say 2 primitive boxes trying to do there best to encompass the shape and since boxes are the fastest primitives 2 boxes is the fastest compound shape. Since i want the triangles to be shot i need the collision detections to be a fairly accurate representation of the shape.
As such I think a mesh triangle is probably best since 8 tri check is still better than say 2 boxes each with a 6 side check.
Thanks for your answer!!
Really well answered question. I was wondering if you could take a look at my question on this matter and give me your input?
Link: http://answers.unity3d.com/questions/1113484/primitive-colliders-vs-mesh-colliders.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613083031im_/https://answers.unity.com/themes/thub/images/avi.jpg)