- Home /
Performance Question: 1 big vs many small mesh colliders
I am procedurally generating a tubular structure. The radius/shape varies over the length of the tubular structure. For my purposes I need accurate physics on that shape. As the tube is constructed by connecting ring A of vertices with ring B of vertices with ring C of vertices etc, etc, I want to know what would be better performance-wise. Should I make the entire tubular structure one mesh for colliders or should I break each ring-to-ring segment into a separate child collider mesh of the parent visible geometry?
Essentially, is it better to have one large multi-segment tubular mesh collider or should I break each segment of the tubular structure into a different mesh collider.
I know that mesh colliders are more expensive. If there were a good way to do this with just spheres I would do that, but I really need as close to precise result as I can get for this application.
Pretty sure size of colliders doesn't really matter. So 1 single collider would always be better. The lower resolution the mesh collider, the better, obviously. Try to avoid many vertices near one another, complex bevels and extrusions, very thin enclosed meshes, etc.
Too bad capsules don't have an option for flat tops...
Thanks for the response. It's not really the size of the collider that's the question. It's the number of triangles in the mesh collider. Is it better to have one large mesh collider with many triangles or multiple mesh colliders with fewer triangles?
I've also thought of child capsules but again they don't approximate the shape well enough for the application. It's one of those rare situations where I really need the collider to be very accurate.
Hmmm, tough call, I would think that splitting it up where it logically makes sense might improve performance by allowing for culling to take place. So if one collider is off frame, while another is on frame, there's less to process, potentially. As long as your splitting doesn't add geometry I'd say splitting is better. But this may be worth profiling to be sure, if performance is key and this is a huge part of your performance.
I'd be curious to know the result of such a test, so please post again with results if you end up testing this out!
Considering that it is a procedurally generated mesh, I suggest you to use the mesh collider.
Now, about 1 big vs many small, you should use one big. Use many small if you need to do something particular with each segment (exploding for example, but I don't feel you're planning to do that).
About performance, I think the less gameObjects/component you have, the less Unity resources/performance you're using.
I see you're new in the Unity community. Welcome. When someone answer your questions, you should vote and check the good answer.
Thanks for the answer. You are right that I don't plan on doing anything with the individual segments. I also think that more objects is more of a problem than one more complex object, but I don't know which is why I asked the question. It seems like I've getting conflicting answers from people; which is fine. $$anonymous$$ostly I wanted to know if it was clearly one option or the other and so I didn't do something inherently wrong.
I am going to go ahead and write two versions of the same program: one that uses one large mesh as you say and one that breaks the mesh into smaller segments. The total triangles should be the same. I won't have time just now to write the different versions but I'll post my results when the experiment is done.
Thanks for the comments. I plan on writing the two options into code and then testing it out. I'll post the results here.
Answer by camander321 · May 10, 2015 at 03:43 PM
I'm sure you've solved this, and I'm not sure how this would scale to your project, but if performance is a concern, this is what I would do.
Create an invisible mesh that copies just the vertices closest to whatever object will be colliding with the tube. I can't imagine this would be too hard, provided that the distance between rings is known and each ring has the same number of vertices. This will give you accurate collisions, but only worry about relevant vertices
Answer by Sisso · Dec 02, 2013 at 07:02 PM
Personally I think that you must split in objects of avarage size. I don't know how unity3d engine works. But exists many types of otimizations used by physic engines to exclude a object from collision test that didn't apply for large or concave objects.
For example, you can have a AABB (http://en.wikipedia.org/wiki/Bounding_volume) for each game object and put into a octree (http://en.wikipedia.org/wiki/Octree), only objects in the same octree node that collide your AABB you must check for mesh colision. For a large mesh, the AABB will always have contact and you must always check for mesh collision.
But in the end, it is better make what is easy for you and test for perfomance.
To me it is also more logically to split mesh into more smaller pieces because of bounding box optimisation.