docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Meta Quest Anchors feature

    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.

    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 following example:

    // 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 and shared anchor GUIDs

    On Meta's OpenXR runtime, the SerializableGuid returned by ARAnchorManager.TrySaveAnchorAsync and ARAnchorManager.TryShareAnchorAsync is the same value as the input anchor's trackableId.

    Batch save anchors

    OpenXR Meta overrides AR Foundation's default implementation for batch save anchors by requesting to save the entire batch at once instead of one at a time. Because of how Meta's OpenXR API is defined, the entire batch either succeeds or fails to save together. In other words, if one anchor fails to save, then all anchors will fail to save.

    Batch load anchors

    OpenXR Meta overrides AR Foundation's default implementation for batch load anchors by requesting to load the entire batch at once instead of one at a time. XRAnchorSubsystem.TryLoadAnchorsAsync will always order successfully loaded anchors in its output results followed by anchors that failed to load.

    Incremental load results

    Unlike AR Foundation's default implementation for XRAnchorSubsystem.TryLoadAnchorsAsync where the incremental results callback is invoked once per anchor, incremental results from OpenXR Meta can contain multiple loaded anchors.

    Batch erase anchors

    OpenXR Meta overrides AR Foundation's default implementation for batch erase anchors by requesting to erase the entire batch at once instead of one at a time. Because of how Meta's OpenXR API is defined, the entire batch either succeeds or fails to erase together. In other words, if one anchor fails to erase, then all anchors will fail to erase.

    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:

    // Marshal the native anchor data from the XRAnchor.nativePtr in C#
    UnityXRNativeAnchor nativeAnchor;
    XrSpace* anchorXrSpaceHandle = static_cast<XrSpace*>(nativeAnchor.referencePointPtr);
    

    To learn more about native pointers and their usage, refer to Extending AR Foundation.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)