Unable to Enable Unbounded Tracking Mode on Magic Leap 2 with OpenXR

Hi,

I'm trying to implement unbounded tracking mode on Magic Leap 2 using OpenXR in Unity, but I'm encountering some issues. I've directly implemented the reference code from the documentation, but the device only supports Device mode and fails to enable unbounded tracking.

Environment:

  • Device: Magic Leap 2
  • Unity Version: 2022.3.53f
  • OpenXR Plugin Version: 1.13.2
  • OS Version: 1.8
  • Magic Leap SDK Version: 2.5.0

Current Setup:

  • OpenXR Magic Leap Reference Spaces Feature is enabled in project settings
  • Tested with XR Origin Tracking Origin Mode set to: Not Specified, Device, and Floor
  • Using the exact reference implementation from the documentation
using System;
using System.Collections;
using System.Linq;
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.XR.Management;
using UnityEngine.XR.OpenXR;
using MagicLeap.OpenXR.Features;
using Unity.XR.CoreUtils;  // Add this for XROrigin

public class ReferenceSpaceToggle : LoggableMonoBehaviour
{
    private bool inputSubsystemValid;
    private XRInputSubsystem inputSubsystem;
    
    [SerializeField]
    private bool setSpaceOnStart = true;

    public override string LogPrefix => "MLReferenceSpace";
    
    void Awake()
    {
        // Changed null check to use GetComponent<XROrigin>() == null
        if (gameObject.GetComponent<XROrigin>() == null)
        {
            LogWarning("ReferenceSpaceToggle should be attached to an XROrigin GameObject for proper functionality");
        }
    }

    IEnumerator Start()
    {
        var referenceSpaceFeature = OpenXRSettings.Instance.GetFeature<MagicLeapReferenceSpacesFeature>();
        if (referenceSpaceFeature == null)  // Changed to explicit null check
        {
            LogError("Magic Leap Reference Spaces Feature not found in OpenXR Settings");
            yield break;
        }

        if (!referenceSpaceFeature.enabled)
        {
            LogError("Magic Leap Reference Spaces Feature is not enabled in OpenXR Settings. Please enable it in Window > XR Plugin Manager > OpenXR Settings");
            yield break;
        }
        else
        {
            LogNormal("Magic Leap Reference Spaces Feature is enabled");
        }

        // Modified null check chain to be more explicit
        while (XRGeneralSettings.Instance == null || 
               XRGeneralSettings.Instance.Manager == null || 
               XRGeneralSettings.Instance.Manager.activeLoader == null || 
               XRGeneralSettings.Instance.Manager.activeLoader.GetLoadedSubsystem<XRInputSubsystem>() == null)
        {
            LogDetail("Waiting for XR Input Subsystem initialization...");
            yield return new WaitForSeconds(0.1f);
        }

        inputSubsystem = XRGeneralSettings.Instance.Manager.activeLoader.GetLoadedSubsystem<XRInputSubsystem>();
        LogNormal("XR Input Subsystem initialized successfully");
        
        // Verify supported tracking modes
        TrackingOriginModeFlags supportedModes = inputSubsystem.GetSupportedTrackingOriginModes();
        
        // Check specifically for Unbounded support
        if (!supportedModes.HasFlag(TrackingOriginModeFlags.Unbounded))
        {
            LogError("Unbounded tracking mode is not supported by the current configuration");
            LogDetail($"Available tracking modes: {supportedModes}");
            yield break;
        }
        else 
        {
            LogNormal("Unbounded tracking mode is supported");
        }

        // Log all supported spaces for debugging
        string supportedSpaces = string.Join("\n",
            ((TrackingOriginModeFlags[])Enum.GetValues(typeof(TrackingOriginModeFlags)))
            .Where(flag => supportedModes.HasFlag(flag) && flag != TrackingOriginModeFlags.Unknown));
        LogDetail($"All supported tracking spaces:\n{supportedSpaces}");

        inputSubsystemValid = true;

        if (setSpaceOnStart)
        {
            LogNormal("Setting initial tracking space to Unbounded");
            SetSpace(TrackingOriginModeFlags.Unbounded);
        }
    }

    public bool SetSpace(TrackingOriginModeFlags flag)
    {
        if (!inputSubsystemValid)
        {
            LogError("Cannot set space - input subsystem not valid");
            return false;
        }

        if (inputSubsystem.TrySetTrackingOriginMode(flag))
        {
            string currentSpace = inputSubsystem.GetTrackingOriginMode().ToString();
            LogNormal($"Successfully set tracking space to: {currentSpace}");
            
            // Recenter the tracking origin
            if (!inputSubsystem.TryRecenter())
            {
                LogWarning("Failed to recenter tracking origin");
            }
            else
            {
                LogDetail("Successfully recentered tracking origin");
            }
            return true;
        }

        LogError($"Failed to set Tracking Mode Origin to {flag}");
        return false;
    }

    void OnDisable()
    {
        // Clean up reference when disabled
        if (inputSubsystem != null)
        {
            LogDetail("Cleaning up input subsystem reference");
            inputSubsystem = null;
            inputSubsystemValid = false;
        }
    }
}

Output:

[MLReferenceSpace] Reference Space Feature is properly configured
[MLReferenceSpace] XR Input Subsystem initialized successfully
[MLReferenceSpace] Currently supported tracking modes: Device
[MLReferenceSpace] Unbounded mode not initially available - attempting to enable...
[MLReferenceSpace] Failed to set Tracking Mode Origin to Unbounded

Current Behavior:

  1. The OpenXR Reference Spaces Feature initializes correctly and is confirmed enabled
  2. XR Input Subsystem successfully initializes
  3. When querying supported tracking modes through GetSupportedTrackingOriginModes(), only TrackingOriginModeFlags.Device is reported
  4. Attempts to enable Unbounded mode fail even after proper initialization and recentering
  5. All other tracking features (Device mode, head tracking, etc.) work normally

Expected Behavior:

  • Unbounded mode should appear in the supported tracking modes
  • Should be able to switch to unbounded tracking mode successfully
  • Should maintain consistent tracking in unbounded space

Troubleshooting Steps Already Attempted:

  1. Verified OpenXR settings configuration multiple times
  2. Ensured proper XROrigin hierarchy and component setup
  3. Tried different initialization sequences including delays between steps
  4. Confirmed no conflicting tracking settings in other components
  5. Tested with both fresh scenes and existing projects

What additional steps are needed to make Unbounded tracking mode available as a supported space? I suspect this might be an initialization sequence issue, but I haven't been able to determine the correct order of operations to enable this feature.

I just tested the API in Unity 6 , OpenXR 1.13.0 and OpenXR 1.13.2

I used the script on the developer portal and was able to set the tracking origin properly. Is the OpenXR XR Plug-in Provider the only provider selected in the Project Settings?

using System;
using System.Collections;
using System.Linq;
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.XR.Management;
using UnityEngine.XR.OpenXR;
using MagicLeap.OpenXR.Features;


public class XRTrackingMode : MonoBehaviour
{

    private XRInputSubsystem _inputSubsystem;


        //{ TrackingOriginModeFlags.Device, TrackingOriginModeFlags.Floor, TrackingOriginModeFlags.Unbounded };

    IEnumerator Start()
    {
      var referenceSpaceFeature = OpenXRSettings.Instance.GetFeature<MagicLeapReferenceSpacesFeature>();
              if (!referenceSpaceFeature.enabled)
              {
                  Debug.LogError("Unbounded Tracking Space cannot be set if the OpenXR Magic Leap Reference Spaces Feature is not enabled. Stopping Script.");
                  yield break;
              }
      
              yield return new WaitUntil(() => XRGeneralSettings.Instance != null &&
                                                XRGeneralSettings.Instance.Manager != null &&
                                                XRGeneralSettings.Instance.Manager.activeLoader != null &&
                                                XRGeneralSettings.Instance.Manager.activeLoader.GetLoadedSubsystem<XRInputSubsystem>() != null);
      
              _inputSubsystem = XRGeneralSettings.Instance.Manager.activeLoader.GetLoadedSubsystem<XRInputSubsystem>();
              TrackingOriginModeFlags supportedModes = _inputSubsystem.GetSupportedTrackingOriginModes();
      
              string supportedSpaces = string.Join("\n",
                   ((TrackingOriginModeFlags[])Enum.GetValues(typeof(TrackingOriginModeFlags))).Where((flag) =>
                       supportedModes.HasFlag(flag) && flag != TrackingOriginModeFlags.Unknown));
              Debug.Log($"Supported Spaces:{supportedSpaces}");
      
              string currentSpace = _inputSubsystem.GetTrackingOriginMode().ToString();
              Debug.Log($"Current Space:{currentSpace}");
      
      
              SetSpace(TrackingOriginModeFlags.Unbounded);

    }

    public void SetSpace(TrackingOriginModeFlags flag)
    {
        if (_inputSubsystem.TrySetTrackingOriginMode(flag))
        {
            Debug.Log(" Tracking Space Now Set To : " + _inputSubsystem.GetTrackingOriginMode());
            _inputSubsystem.TryRecenter();
        }
        else
        { 
            Debug.LogError("SetSpace failed to set Tracking Mode Origin to " + flag);
        }
    }
}
1 Like

This did the trick, thanks!

I also had Magic Leap 2 selected, and after removing it, everything worked.

1 Like