Raycast returning incorrect collider when cast from screen point

I’m casting a ray from a screen point like this:

Vector3 rayPoint = Input.mousePosition;
var ray = Camera.main.ScreenPointToRay(rayPoint);
Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow);
if(Physics.Raycast(ray, out hit))
    Debug.Log(hit.collider.gameObject.name);

If you look at my screenshot that I have attached, you can clearly see that my yellow line is hitting the black object first, then going through to the “rock” behind it. However, my debug.log call is outputting “LeftRock” instead of the “CaveDoor”.

I have no idea why. You can clearly see the ray hitting the “CaveDoor” first.

Are you ever ignoring collisions between layers? You can setup a layer for your door and ignore all other layers when you raycast I suppose. A better explanation is given here: Help With Ignoring Collider With Raycast!? - Unity Answers