Managing AR Raycast in Unity

Paul Killman
Antaeus AR
Published in
2 min readFeb 16, 2024

According to the AR Foundation Manual, “Ray casting allows you to determine where a ray intersects with a trackable.” If you are unfamiliar with ray casting, imagine an invisible laser beam that starts at an origin point, (usually the camera), and then proceeds along a given direction and distance or to a specified point.

AR raycasting is a little different than the physics raycasting used in non-AR projects. AR ray casts are optimized for AR environments and provide the best and most reliable performance.

In this article, I will be using ray casting to detect what is at a position that I touch on the screen. (I’m assuming that you already have an AR project set up in Unity. If not, please see this article.)

The first step is to add an AR Raycast Manager to your XR Origin.

I am not going into scripting in this article, just the AR Raycasting setup. Sample scripts can be found in the AR Foundation Manual.

--

--