I’m not sure if this is a bug, but this has driven me crazy until I realized that I had to enable the “Convex” check on the Mesh Collider in order to make this function work.
I really need to make ClosestPoint function work without enabling that option. Any idea or workaround?
Hm, it does appear to be either a bug or an oversight in the documentation page, as the doc does not mention that the method only works on convex MeshColliders. My guess would be that it’s more of a documentation issue, because there are a LOT of things that only work for convex MeshColliders.
The common workaround for these sorts of things is to split a concave MeshCollider into multiple convex ones. It’s not great solution but it works, and IIRC there are some packages available (maybe on the asset store?) that can automatically break apart concave meshes into convex ones.
For anyone stumbling across this, you can turn a non-closed mesh collider into a convex mesh collider programmatically thus:
MeshCollider m = GetComponent<MeshCollider>();
m.convex = true;
Note from https://docs.unity3d.com/ScriptReference/MeshCollider-convex.html:
A convex mesh is required by the physics engine to have a non-zero volume. Flat meshes such as quads or planes that are marked as convex will be modified by the physics engine to have a thickness (and therefore a volume) to satisfy this requirement. The thickness of the resulting mesh is proportional to its size and can be up to 0.05 of its longest dimension in the plane of the mesh.