Question - Raycast only works in Editor

So, I have a raycast that looks like this:

Ray ray = cachedCamera.ViewportPointToRay(new Vector3(.5f, .45f, 0));
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit, 500, layerToIgnore.value) && hit.point != focalPoint) {
focalPoint = hit.point;
focalPointAssigned = true;
}

So, weird time. If I use this as is in an editor build, it is perfect. If I use this as is in an actual build, it doesn’t focus at all, or the focusing makes no sense (I.e. look in a weird direction and blocks suddenly focus).

But then if I remove the distance and layer mask, it works like a charm (this does not work for me, however, because I need to be able to ignore certain things).

Is this a known bug?

A quick point - the layermask is properly inverted to ignore, and runs excellently in the editor.