RaycastAll returns different results than Collider.Raycast

I’m having serious issues with RaycastAll not hitting all colliders on its path. The simple example:

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

The results I’m getting (one of them):

Raycast all gave 1 hits:MissileExplosion(Clone);
Manually verified, that ray hits MissileExplosion(Clone)
Manually verified, that ray hits Falcon(Clone)

Note, that origin of ray is (in this case) not inside any of colliders. The game is 2,5D, camera floats above plane of action, there’s no way it may finish up inside any of colliders.

The thing that may be important is that timeScale during the presented scenario is 0 (physics is paused).

Can timeScale being 0 cause such issue? How can I resolve it, should I resign from using RaycastAll? Is it a bug in Unity libraries?

This is puzzling. I personally haven’t used Collider.Raycast (versus Physics.Raycast). Looking it up, the former will only ever hit the given collider, as long as the ray intersects it. Do you get more consistent behavior if you replace Collider.Raycast with Physics.Raycast? Meaning, do you at least only hit the MissileExplosion, and not hit the Falcon in that case?

So far I don’t have any ideas as to why your falcon would be treated differently. If you put a few missiles in the ray’s path, does RaycastAll hit all the missiles? Just trying to narrow down whether this is an issue specific to your Falcon collider. Could you post a screenshot of what your Falcon collider looks like? Or, the whole game object, so we can see the layer its on?

About Physics.Raycast - I might try, but I doubt it will give valid results in this case (especially since Physics.RaycastAll seems to behave incorrectly). Collider.Raycast tests only one specific collider against the ray, whereas Physics.Raycast tests all colliders and then returns information about one hit collider only (presumably, first on the path of the ray). I guess Physics.Raycast does the same as Physics.RaycastAll, but returns only one hit collider instead of all of them.

The ray I’m talking about is actually a “mouse ray” - originating from the camera through screen to clicked place. I might put missiles there, though that would have to be artificial, since objects would never get there as game is 2.5D (gameplay takes place on a OXZ plane).

I posted a question on Stackoverflow as well - there are more details about this issue, including Falcon’s collider shape and a few screenshots, could you please take a look there?

https://gamedev.stackexchange.com/questions/159542/why-raycastall-misses-some-objects

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.

Sorry for necroing, but do you have the bug report number or link available? Was this ever fixed? The StackExchange answer reports the same thing (confirmed bug) but without a tracking either. I’m getting the same issue in Unity 2020.3.48f1 and want to make sure it’s not on my end.