Raycast returning inconsistent hits, especially in edit mode

I’ve been going mad debugging an issue where the raycasts return inconsistent results – sometimes they hit the colliders, sometimes they don’t, but eventually succeed and stabilize, consistently hitting the colliders.

The thing is nothing changes in the scene. It is entirely static, no user manipulation happens, no movement, not even rigidbodies, all static colliders, exactly the same raycast (debugged and logged every way I could think of) over contiguous frames.

It especially (but not exclusively) seems to happen in the editor and for the first few frames after a collider’s game object has been selected. This leads me to wonder if Unity waits until initializing colliders for performance reasons, but I can’t find anything in the documentation or on Google about this after multiple hours of searching.

One perhaps important thing to note is that most colliders in question are MeshColliders.

I tried calling Physics.SyncTransform(), but it doesn’t help. I’ve also tried disabling-reenabling the colliders, and calling MeshCollider.BakeMesh(), to no avail.

Is this a known behaviour? Can I force Unity to instantly initialize its colliders or physics data?

Are raycasts, even on static scenes, simply non-deterministic?

Unity 2020.3.48f1