Anchors
This page is a supplement to the AR Foundation Anchors manual. The following sections only contain information about APIs where Meta Quest exhibits unique platform-specific behavior.
Tip
When developing an AR app, refer to both the AR Foundation documentation as well as the required packages for each platform you support.
Optional feature support
Meta OpenXR implements the following optional features of AR Foundation's XRAnchorSubsystem:
Feature | Descriptor Property | Supported |
---|---|---|
Trackable Attachment | supportsTrackableAttachments | |
Synchronous Add Anchor | supportsSynchronousAdd | |
Save Anchor | supportsSaveAnchor | Yes |
Load Anchor | supportsLoadAnchor | Yes |
Erase Anchor | supportsEraseAnchor | Yes |
Get Saved Anchor Ids | supportsGetSavedAnchorIds | |
Async Cancellation | supportsAsyncCancellation |
Platform-specific success and error codes
On OpenXR platforms, the XRResultStatus.nativeStatusCode returned by AR Foundation's ARAnchorManager.TryAddAnchorAsync is a wrapper around OpenXR's XrResult.
You can use the XRResultStatus.nativeStatusCode
property to access the underlying XrResult
value, as shown in the example below:
// This is not optimal. For better performance, reuse a saved reference instead.
var anchorManager = Object.FindAnyObjectByType<ARAnchorManager>();
// Create an anchor at an arbitrary pose.
// You could modify this code to use the position of a raycast hit instead.
var pose = new Pose(Vector3.zero, Quaternion.identity);
var result = await anchorManager.TryAddAnchorAsync(pose);
// To access OpenXR error and success codes, use the nativeStatusCode property
var xrResult = (XrResult)result.status.nativeStatusCode;
// Prints "Success", or the error or success code associated with this operation
Debug.Log(xrResult);
Persistent anchor GUIDs
On Meta's OpenXR runtime, the SerializableGuid
returned by ARAnchorManager.TrySaveAnchorAsync is the same value as the input anchor's trackableId.
Native pointer
XRAnchor.nativePtr values returned by this package contain a pointer to the following struct:
typedef struct UnityXRNativeAnchor
{
int version;
void* referencePointPtr;
} UnityXRNativeAnchor;
Cast the void* referencePointPtr
to an XrSpace handle in C++ using the following example code:
// Marhshal the native anchor data from the XRAnchor.nativePtr in C#
UnityXRNativeAnchor nativeAnchor;
XrSpace* anchorXrSpaceHandle = reinterpret_cast<XrSpace*>(&nativeAnchor.referencePointPtr);
To learn more about native pointers and their usage, refer to Extending AR Foundation.