There’s a lot of flavors of raycast… you can actually raycast directly against a specific collider, which ignores everything else.
Raycasting, colliders, planes, Plane, etc:
And there is also EventSystem.RaycastAll for raycasting in the UI / EventSystems context.
Raycasting in 2D: