Physics.Raycast intermittently stops working

After our game has been running for a little while, every call to Physics.Raycast returns false for a little while. The problem comes and goes. Raycasts may stop working for a couple seconds, work again for 30 seconds, and then fail again. We’re in a panic getting ready for a demo and aren’t sure how to track this down.

When the problem happens, all raycasts in the game fail. User interface (NGUI) raycasts. Raycasts from the camera that we use to pick game objects. Even a fixed raycast that we perform every frame into an object that never moves. They all return false. We can pause the game and check that the objects we expect to hit still exist, are enabled, and have an enabled MeshCollider attached.

Any ideas of what we could be doing to cause this or how to narrow the problem down?

We eventually tracked this problem down to animated characters with a CapsuleCollider. The problem didn’t reproduce if we replaced the CapsuleCollider with a SphereCollider. We could pause in the editor, disable CapsuleCollider on some objects, unpause, and raycasts would start working again the next frame.

Based on discussions with other teams, it sounds like Unity’s CapsuleCollider has bugs with animating/moving/rotating objects.

Although they have different symptoms, here are some related issues about CapsuleColliders:

http://answers.unity3d.com/questions/126005/the-abnormal-mistery.html

http://www.youtube.com/watch?v=wQAl-k8oRZk&t=9m30s

For now, we’re prohibiting use of CapsuleCollider in our game and that has fixed the problem 100%.