- Home /
RaycastAll vs Collider.Raycast gives different results
RaycastAll is supposed to return all objects on the path of the ray for specified distance, right?
RaycastHit[] hits = Physics.RaycastAll(ray, float.PositiveInfinity);
// DEBUG
string debug = "Raycast all gave " + hits.Length + " hits:";
for (int i = 0; i < hits.Length; i++)
debug += hits[i].collider.gameObject.name + "; ";
Debug.Log(debug);
var colliders = GameObject.FindObjectsOfType<Collider>();
foreach (var collider in colliders)
{
RaycastHit temp;
if (collider.Raycast(ray, out temp, float.PositiveInfinity))
{
Debug.Log("Manually verified, that ray hits " + collider.gameObject.name);
}
}
// END DEBUG
On some occasions, I'm getting:
Raycast all gave 1 hits:MissileExplosion(Clone);
Manually verified, that ray hits MissileExplosion(Clone)
Manually verified, that ray hits Falcon(Clone)
Shouldn't RaycastAll return the same set of results? What may cause that? Is it a bug in Unity?
Answer by wojciechsura · Jun 13, 2018 at 07:31 AM
I filed a bug report and Unity QAs managed to reproduce it. It have been sent do Unity devs and hopefully will be fixed in upcoming release of the editor.
Answer by SofiaFeist · Apr 03, 2020 at 08:53 PM
Apparently, the bug still hasn't been fixed because I'm getting the same error...
Answer by kankane · Jun 24, 2020 at 05:34 PM
I am having the same problem in 2019.3. Is there a way to check bug reports and see if it's still open?
Your answer
![](https://koobas.hobune.stream/wayback/20220612164311im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why RaycastAll misses some objects? 1 Answer
Inconsistent collision detection on slow-moving objects 0 Answers
How to activate a collider only for a certain animation, and then deactivate it 1 Answer
Rigidbody gets stuck in wall after falling 0 Answers
Is their a way to change boxcollider2d's method of detection? 1 Answer