A compound collider is a collection of colliders on the same Rigidbody GameObject.
Compound colliders collectively behave like a single Rigidbody collider. They are useful when you need an accurate collider for a concave shape, or if you have a model that would be too computationally demanding to simulate with a Mesh collider.
A compound collider is made of the following elements:
A compound collider should only have one Rigidbody, which should be on the root GameObject.
For more guidance on how to create a compound collider, see Create a compound collider.
In the above picture, the Gun Model GameObject has a Rigidbody attached to its parent GameObject, and several child GameObjects that each have a primitive collider. When physics forces move the Rigidbody parent, the child colliders move along with it. The primitive colliders can collide with other colliders in the environment, and the parent Rigidbody alters the way it moves based on these collisions.
This configuration offers more flexibility than a single GameObject that contains a Rigidbody and several colliders. When each collider is on a different GameObject, you can modify the Transform of each collider individually. However, you should monitor the Rigidbody’s behavior when you reposition colliders. Changes to collider position and scale can change the Rigidbody’s center of mass, which can result in some unexpected behavior if continuous change is made over several frames at runtime. If this happens, you can use rigidbody.centerOfMass
to manually set the center of mass.
When you attach several colliders to the same Rigidbody, the physics system treats the whole collection as a single Rigidbody collider. The collider type (dynamic or kinematic) is defined by the Rigidbody configuration.
When a compound collider touches another collider, Unity registers collisions per each individual collider in the compound. For this reason, you should try to arrange your colliders so that you only get the collision pairs you want at runtime, or use collider labels to determine behaviors caused by specific colliders.
In most cases, compound colliders offer a similar solution to Mesh colliders: their primary purpose is to provide accurate collisions for items with complex shapes. When considering the benefits and limitations of compound colliders, you are usually comparing them to Mesh colliders.
The main benefits of compound colliders are: * You can get collisions for complex concave shapes. Mesh colliders are more accurate, but they don’t support accurate collisions for concave shapes. * In some cases, compound colliders can be less computationally demanding than Mesh colliders. This is often the case for simpler shapes which only require a few colliders to approximate, or for shapes that don’t need to be too accurate. For example, a Mesh collider might generate hundreds of polygons in order to precisely match a complex shape, but an approximation with primitive colliders might require far fewer.
However, compound colliders also have some significant limitations: * Compound colliders are not as accurate. In most cases, you build a compound collider out of simpler shapes, which allow you to approximate but not perfectly match the shape of the item. * Compound colliders take longer to produce. Compound colliders require you to arrange each collider manually, which takes more time. * In some cases, compound colliders can be more computationally demanding than Mesh colliders. This is often the case for very complex shapes which require a high number of colliders to approximate. One Mesh collider might be more efficient than several primitive colliders.
The decision is always unique to your project, so you should test each configuration and use the Physics Profiler to understand the efficiency of your collider setup.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.