What is difference between XRRaycastHit and XRRaycast?

Hello.
I’ve read documentation XRRaycastHit and XRRaycast.
However, I couldn’t understand the difference between two.
Can you teach me when to use these in different ways?

https://docs.unity3d.com/Packages/com.unity.xr.arsubsystems@4.0/api/UnityEngine.XR.ARSubsystems.XRRaycast.html
https://docs.unity3d.com/Packages/com.unity.xr.arsubsystems@4.0/api/UnityEngine.XR.ARSubsystems.XRRaycastHit.html

XRRaycast is a tracked raycast that updates over time. Calling ARRaycastManager.AddRaycast() will return
ARRaycast (which is a managed wrapper for XRRaycast). Then use can subscribe to its Action<ARRaycastUpdatedEventArgs> updated event to listen when XRRaycast updates its precision.

XRRaycastHit on the other hand, is a data holder that contains information about raycast hit. You get it from calling ARPlaneManager.Raycast() and ARPointCloudManager.Raycast().

For most of usages ARPlaneManager.Raycast() will be enough. But if you’re looking for the best precision, then look for ARRaycastManager.AddRaycast().

Thank you for the reply.
So when I use ARRaycastManager.AddRaycast(), ARRaycastManager instantiates prefab that GameObject has ARRaycast component on it like ARPlaneManager. Is that correct?

I experimented with it yesterday, and its behavior is not very obvious.
Yes, ARRaycastManager will spawn prefab with ARRaycast component on the intersection between ray coming from screen position and detected plane. Then ARRaycast will update its position automatically when a new more precise position is received.

Thank you for your experiment.

I’ve got raycast component by calling AddRaycast like this.
ARRaycast raycast = raycastManager.AddRaycast(touchPosition, 5);
Then I’m trying to get position of the object. How should I get it?

ARRaycast is a MonoBehavior so you can get its position by raycast.transform.position. But check for null first.

Many thanks. I got it.