A compound colliderAn invisible shape that is used to handle physical collisions for an object. A collider doesn’t need to be exactly the same shape as the object’s mesh - a rough approximation is often more efficient and indistinguishable in gameplay. More info
See in Glossary is a collection of colliders on the same RigidbodyA component that allows a GameObject to be affected by simulated gravity and other forces. More info
See in Glossary GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary.
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 colliderA free-form collider component which accepts a mesh reference to define its collision surface shape. More info
See in Glossary.
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 collisionsA collision occurs when the physics engine detects that the colliders of two GameObjects make contact or overlap, when at least one has a Rigidbody component and is in motion. More info
See in Glossary.
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 massRepresents the average position of all mass in a Rigidbody for the purposes of physics calculations. By default it is computed from all colliders belonging to the Rigidbody, but can be modified via script. More info
See in Glossary, 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 MeshThe main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
See in Glossary colliders.
The main benefits of compound colliders are:
However, compound colliders also have some significant limitations:
The decision is always unique to your project, so you should test each configuration and use the Physics ProfilerA window that helps you to optimize your game. It shows how much time is spent in the various areas of your game. For example, it can report the percentage of time spent rendering, animating, or in your game logic. More info
See in Glossary to understand the efficiency of your collider setup.