Skip to main content
Version: 21 Aug 2024

Migrating from ML1

This article provides an overview on the changes that were made to the Magic Leap SDK and how to access Magic Leap 1 equivalent features on the Magic Leap 2.

Both Magic Leap 1 and Magic Leap 2 define these APIs under the UnityEngine.XR.MagicLeap namespace.

API Transition Table

TopicMagic Leap 1Magic Leap 2
StateMLHeadTracking.GetState(out State state)MLHeadTracking.TryGetStateEx(headDevice, out MLHeadTracking.State state);
Map EventsDelegates were exposed but didn't workMLHeadTracking.TryGetMapEvents(headDevice, out MLHeadTracking.MapEvents mapEvents);
info

Head tracking state provides information like tracking mode, confidence and reason for tracking errors.

Overview

using UnityEngine.XR.MagicLeap;
using InputDevice = UnityEngine.XR.InputDevice;
using static UnityEngine.XR.MagicLeap.InputSubsystem.Extensions;


private InputDevice headDevice;
...
// Initialize headDevice in Start() or Update()
headDevice = InputSubsystem.Utils.FindMagicLeapDevice(InputDeviceCharacteristics.HeadMounted | InputDeviceCharacteristics.TrackedDevice);

// Access the head tracking state
MLHeadTracking.TryGetStateEx(headDevice, out MLHeadTracking.StateEx state);
// Access the head tracking map events
MLHeadTracking.TryGetMapEvents(headDevice, out MLHeadTracking.MapEvents mapEvents);

See also