Optimize CPU performance by selecting the most appropriate 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 type for your sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary.
Choosing the right collider type directly affects CPU performance. Unity has several collider types, each with different computational costs.
To learn more about 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 Collider component properties, refer to Mesh collider component reference.
To learn more about collider interactions, refer to Collider interactions.
The following table summarizes the collider types and their performance characteristics in order from most to least performant:
Collider type | Performance characteristics |
---|---|
Sphere ColliderA sphere-shaped collider component that handles collisions for GameObjects like balls or other things that can be roughly approximated as a sphere for the purposes of physics. More info See in Glossary |
The simplest and most efficient collider. Use for round objects and general-purpose interactions. |
Capsule ColliderA capsule-shaped collider component that handles collisions for GameObjects like barrels and character limbs. More info See in Glossary |
Slightly more complex than a Sphere Collider, but still efficient. Use for characters, poles, or other elongated shapes. |
Box ColliderA cube-shaped collider component that handles collisions for GameObjects like dice and ice cubes. More info See in Glossary |
Efficient and flexible, especially for rectangular or block-shaped objects. Slightly more resource-intensive than Sphere Collider or Capsule Collider. |
Convex Mesh Collider | More resource-intensive than primitive colliders. Use only when primitive shapes or compound colliders cannot approximate the geometry. The mesh must be convex. You can attach this to GameObjectsThe 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 with non-kinematic RigidbodyA component that allows a GameObject to be affected by simulated gravity and other forces. More info See in Glossary components attached. |
Non-convex Mesh Collider | A Mesh Collider with Convex unchecked. The most resource-intensive collider type. Use only for static, non-moving geometry that requires precise collisionA 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 surfaces. Cannot be attached to non-kinematic Rigidbodies. |
Compound colliders are formed by parenting multiple primitive colliders, such as Sphere, Box, and Capsule colliders, to a single GameObject with a Rigidbody component. You can use compound colliders, which are comprised of simple components, to approximate complex shapes. Compound colliders are generally more efficient than using a single, complex Mesh Collider for a dynamic object, but they’re more resource-intensive than a single primitive collider.
Use as few primitive colliders as possible within a compound setup to have effective collision detectionAn automatic process performed by Unity which determines whether a moving GameObject with a Rigidbody and collider component has come into contact with any other colliders. More info
See in Glossary.
To learn more about compound colliders, refer to Compound colliders.
Use Compound colliders when:
Rigidbody
cannot do because a single Mesh Collider must be convex.
Mesh Collider components require a preprocessing step called “mesh cooking” to convert their geometry into an optimized format for efficient physics calculations. If this cooking occurs at runtime, it can cause significant CPU performance spikes.
To learn more about Mesh Collider components, refer to Mesh collidersA free-form collider component which accepts a mesh reference to define its collision surface shape. More info
See in Glossary.
You can avoid mesh cooking at runtime by doing the following:
Physics.BakeMesh
for all dynamic cases and you want to potentially reduce build and Editor processing times.Physics.BakeMesh
: For meshes assigned or procedurally generated at runtime, use Physics.BakeMesh(meshInstanceId, convex, cookingOptions)
to explicitly control when cooking occurs. Preferably use Physics.BakeMesh
during loading screens or in background threads if you use the job system.