Managing the AR Raycast | AR Unity Developer

Derek Anderson
2 min readApr 10, 2024

--

With the AR app built to Android, it’s time to explore more about AR development. The next topic to look at is the AR Raycast.

AR Foundation has it’s own type of raycast called an AR raycast. They are similar to a physics raycast and accomplish the same thing. However, AR raycasts are specifically used for AR environments because they are more accurate and have better performance compared to physics raycasts in an AR environment. In addition, AR raycasts can hit the same objects as physics raycasts, so there isn’t really a downside to using AR raycasts in AR environments.

Add an AR Raycast Manager component to the XR Origin, and we’re done with AR Raycasts.

It might seem like there is more to do, but right now there isn’t. A Raycast Prefab could be created, but one will be created with the AR Raycast Manager.

What will the raycasts be for? The XR Interaction Toolkit, just like with VR, can interact with the AR project without the need for code. One of these interactions is the AR Placement Interactable, which will be used to place objects on planes. The AR Placement Interactable will communicate to the AR Raycast Manager, get information about what the raycast hit and place it in the placement prefab spot.

This will be handled with a tap gesture, and an AR Gesture Interactor will map that tap to the AR Placement Interactable when a user taps the screen, which I’ll cover next time.

--

--