Ray cast platform support
The AR Foundation XRRaycastSubsystem is supported on the ARCore, ARKit, Microsoft HoloLens, Meta OpenXR, and XR Simulation platforms, as shown in the following table:
Provider plug-in | Ray casting supported | Provider documentation |
---|---|---|
Google ARCore XR Plug-in | Yes | Ray casts (ARCore) |
Apple ARKit XR Plug-in | Yes | Ray casts (ARKit) |
Apple visionOS XR Plug-in | ||
Microsoft HoloLens | Yes | N/A |
Unity OpenXR: Meta | Yes | Ray casts (Meta OpenXR) |
XR Simulation | Yes | Ray casts (XR Simulation) |
Check for ray casting support
Your app can check at runtime whether a provider plug-in supports ray casting on the user's device. Use the following example code to check whether the device supports ray casting:
void Start()
{
if (LoaderUtility
.GetActiveLoader()?
.GetLoadedSubsystem<XRRaycastSubsystem>() != null)
{
// XRRaycastSubsystem was loaded. The platform supports ray casts.
}
}
Note
This example code assumes that your app has already initialized XR.
By default XR initializes automatically when your app starts, but this is configurable via Project Settings > XR Plug-in Management > Initialize XR on Startup. Refer to the XR Plug-in Management End-user documentation for more detailed information about managing the XR Plug-in lifecycle.
Optional features
The following table lists the optional features of the XRRaycastSubsystem. Each optional feature is defined by a Descriptor Property of the XRRaycastSubsystemDescriptor, which you can check at runtime to determine whether a feature is supported. Refer to Check for optional feature support for a code example to check whether a feature is supported.
Feature | Descriptor Property | Description |
---|---|---|
Viewport based raycast | supportsViewportBasedRaycast | Whether the provider supports casting a ray from a screen point. |
World based raycast | supportsWorldBasedRaycast | Whether the provider supports casting an arbitrary ray. |
Trackable types | supportedTrackableTypes | The types of trackables against which ray casting is supported. |
Tracked raycasts | supportsTrackedRaycasts | Whether tracked raycasts are supported. A tracked raycast is repeated over time and the results are updated automatically. |
Optional feature platform support
The following table lists whether certain XR plug-in providers support each optional feature:
Feature | ARCore | ARKit | Meta OpenXR | XR Simulation |
---|---|---|---|---|
Viewport based raycast | Yes | Yes | ||
World based raycast | Yes | Yes | Yes | |
Tracked raycasts | Yes | iOS 13+ |
Note
The Meta OpenXR ray cast implementation performs calculations in Unity world space and does not rely on native platform implementation. Refer to the Meta OpenXR Ray cast documentation to understand ray casting on Meta OpenXR devices.
Supported trackables
ARRaycastManager supports ray casting against most TrackableTypes. The following table shows which trackables each platform supports ray casting against:
TrackableType | ARCore | ARKit | Meta OpenXR | XR Simulation |
---|---|---|---|---|
BoundingBox | Yes | |||
Depth | Yes | |||
Face | ||||
FeaturePoint | Yes | Yes | Yes | |
Image | ||||
Planes | Yes | Yes | Yes | |
PlaneEstimated | Yes | Yes | Yes | |
PlaneWithinBounds | Yes | Yes | Yes | Yes |
PlaneWithinInfinity | Yes | Yes | ||
PlaneWithinPolygon | Yes | Yes | Yes |
Check for optional feature support
Your app can check at runtime whether a ray casting provider supports any optional features on the user's device. The XRRaycastSubsystemDescriptor contains Boolean properties for each optional feature that tell you whether they are supported.
Refer to the following example code to learn how to check for optional feature support:
void CheckForOptionalFeatureSupport()
{
// This is inefficient. You should re-use a saved reference instead.
var manager = Object.FindAnyObjectByType<ARRaycastManager>();
// Use manager.descriptor to determine which optional features
// are supported on the device. For example:
if (manager.descriptor.supportsWorldBasedRaycast)
{
// World based ray casts are supported.
}
}
Apple and ARKit are trademarks of Apple Inc., registered in the U.S. and other countries and regions.