UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

physics

[PhysX] Fix Inaccurate Convex Mesh Collider Precision

Solution

physicscollisionboxcolliderperformancegeometrycollision detection

Unity 2019.4.x - Unity 6.3.x

Published 14 days ago

Issue

 When applying a convex Mesh Collider to a complex geometry, the resulting collision hull often forms a simplified, enclosing convex shape that ignores concave features, leading to inaccurate collision detection that does not precisely match the visual mesh.

Achieve high-fidelity collision by using Convex Decomposition to break complex geometry into multiple simple convex child colliders.

Explanation

To achieve more precise collision detection for complex objects that require convex colliders, it is recommended to perform Convex Decomposition on your root object to create multiple, simpler convex sub-meshes. Each of these sub-meshes should be created as a separate child GameObject of your root object. This strategy allows for the aggregation of several smaller convex collision shapes, which together can form a more accurate representation of the object’s overall physical boundaries than a single, large convex hull.

  1. Divide your root object into several simplified sub-meshes using a 3D modeling tool or a Convex Decomposition utility.
  2. Import the resulting meshes as child GameObjects under your root object.
  3. Add a Mesh Collider component to each child GameObject.
  4. Enable the Convex property on every Mesh Collider.
  5. Remove the Mesh Renderer from child objects to ensure only the visual mesh of your root object is visible.

Additional Tips:

  • Ensure the Rigidbody is placed on your root object; Unity automatically combines child colliders into a single compound collider.
  • Use the Cooking Options on the Mesh Collider to optimize how the physics engine processes the mesh data.
  • If your root object is dynamic, remember that Mesh Collider components must have the Convex flag enabled to collide with other Mesh Collider components.

Related Posts Haven't quite found a solution to your problem? We think these posts might help you.

Content inspired by a Unity discussion post.