Mesh Collider not working with ray casting for some meshes

Hi

We are rendering certain scenes of physical structures in Unity as triangle meshes. These structures are generally quite large in world space, and we scale each scene down to a unit-cube before rendering with lighting enabled. Each mesh also has a mesh collider that is used to implement picking using ray casting (Physics.Raycast).

When we initially used Unity 5.5, all this worked perfectly. However, after upgrading to Unity 5.6 and 2017.1, we found that lighting no longer worked for these meshes, due to some changes in Unity’s lighting model. We were able to get around this by scaling the vertices down in their local space and applying a scale-up transform over the corresponding game object. This fixed the lighting issue, but has caused the mesh colliders to stop working for one of the scenes. When we enabled the physics debugger windows and enabled the collider view for that scene, it looked like the mesh was being setup correctly (see screenshot). Clicking on in in sceneview causes it to be highlighted properly, meaning Unity is able to pick the object correctly. However, in game mode, when we click on the same mesh and call Physics.Raycast() with the corresponding location, the mesh colliders work in one scene, but not the other.

We suspect this might be something to do with the floating-point resolution in the calculations required for ray-casting, but we are not sure how to get around this. The transforms themselves, including the scale-up transform, and the scaled-down vertices must be correct, since they are being displayed properly.

If anyone has any suggestions on how to get the mesh collider to work under these conditions, it would be much appreciated.

Kind regards
Gautham Ganapathy

This is (mostly) a shot in the dark, but if you haven’t found a solution to this yet, try disabling and reenabling the collider in the Inspector while in play mode. If the collider is suddenly working again after that, I may have an answer for you.