Raycasting in the editor finds all the objects in the scene with a collider. However, on the device, it only hits the cube object. The device’s camera is an AR camera, as you can see, while in the editor, I am using a regular camera. Do you have any idea why it doesn’t detect the spheres when it’s on the device? I am out of ideas regarding what I should check.


Here’s the code for casting rays:
if (overlay.activeSelf) return;
Ray ray = arCamera.ScreenPointToRay(arCamera.ViewportToScreenPoint(pointerViewportPosition));
RaycastHit hit;
bool raycastHit = Physics.Raycast(ray, out hit);
//ConsoleLog(raycastHit.ToString());
AddLineRender(ray);
if (raycastHit)
{
ConsoleLog(hit.transform.name);
activePoint = hit.transform.gameObject;
if (activePoint == previousActivePoint)
{
return;
}
if (previousActivePoint != null && previousActivePoint != activePoint)
{
string pathName = previousActivePoint.transform.parent.name;
Color pathColor = paths.Find(_ => _.name == pathName).color;
previousActivePoint.GetComponent<Renderer>().material.SetColor("_Color", pathColor);
}
activePoint.GetComponent<Renderer>().material.SetColor("_Color", Color.red);
activeLight.SetActive(true);
activeLight.transform.position = activePoint.transform.position;
nameLabel.transform.position = new Vector3(
activePoint.transform.position.x,
activePoint.transform.position.y + .05f,
activePoint.transform.position.z - .05f
);
TextMeshPro tmp = nameLabel.GetComponentInChildren(typeof(TextMeshPro)) as TextMeshPro;
tmp.text = activePoint.transform.parent?.name ?? "";
nameLabel.transform.rotation = placement.rotation;
nameLabel.transform.Rotate(0f, 180.0f, 0f);
nameLabel.SetActive(true);
Vector2 tb = tmp.GetPreferredValues(activePoint.transform.parent?.name);
animationHeight = (tb.y + 2) * .015f;
float dx = ((tb.x / 2) + 1) * .015f + .025f;
float dy = animationHeight - 2;
openingIndicator.transform.position = new Vector3(
activePoint.transform.position.x - dx,
activePoint.transform.position.y + .05f - dy,
activePoint.transform.position.z - .05f
);
openingIndicator.transform.rotation = placement.rotation;
openingIndicator.SetActive(true);
isAnimating = true;
previousActivePoint = activePoint;
if (showOverlay != null)
{
StopCoroutine(showOverlay);
}
showOverlay = ShowOverlay(hit);
StartCoroutine(showOverlay);
}
else
{
activeLight.SetActive(false);
if (previousActivePoint != null)
{
if (showOverlay != null)
{
StopCoroutine(showOverlay);
showOverlay = null;
}
ResetAnimation();
string pathName = previousActivePoint.transform.parent.name;
Color pathColor = paths.Find(_ => _.name == pathName).color;
previousActivePoint.GetComponent<Renderer>().material.SetColor("_Color", pathColor);
previousActivePoint = null;
}
}