- Home /
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?
Does the game animation appear to slow down when this happens?
Have you modified your layers but not your masks?
Answer by ForrestTrepte · Oct 17, 2013 at 04:58 PM
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%.
http://answers.unity3d.com/questions/550691/game-stutter-on-movement.html
Read Shadow$$anonymous$$'s comments, perhaps see if its related.
I cannot thank you enough for this comment. You have made me so happy, I thought my project was bugged to no end and was going to revert in a few $$anonymous$$utes! Thank you SO much!