Quick Start
This section covers how to use the Magic Leap 2 Controller Interaction Profile with Input System. For more information about obtaining OpenXR Input see Unity's OpenXR Input Documentation.
As a result of Magic Leap’s reduced latency for the controller data stream implemented in the 1.5.0 OS release, we recommend that developers relying on controller tracking information (e.g. pose) when interacting with scene objects - such as UI or other virtual content - add some amount of drag inertia to the scene objects. This way, the objects "follow" the controller pose over time as opposed to moving 1:1 to where the controller is pointing, as the high controller sensitivity could result in an undesirable amount of movement.
Enable the Magic Leap 2 Controller Interaction Profile
The Magic Leap 2 Controller Interaction Profile in Unity's OpenXR plugin exposes a specific device layout named <MagicLeapController>
within the OpenXR runtime.This enables interaction with the controller's inputs, such as pointer pose.
This section includes instruction on how to enable the Magic Leap 2 Controller Interaction Profile in your Unity project.
- Navigate to Project Settings > XR Plug-in Management.
- Verify that the OpenXR and Magic Leap feature group options are selected in the Plug-in Providers.
- Next navigate to the OpenXR settings by selecting OpenXR in the Project Settings window.
- Click the + button in the Enabled Interaction Profiles panel.
- Select Magic Leap 2 Controller Interaction Profile from the list of available profiles.
Binding Input Actions
This section provides a brief overview on how to read input from a Magic Leap 2 controller using an InputAction
. For a more in depth guide, see the Unity Input System and OpenXR Input guides.
This example demonstrates initializing an action with the generic trigger button binding and logging a message while the trigger is pressed.
For a complete list of Magic Leap 2 Controller bindings, see the Controller Input Bindings Documentation.
using UnityEngine;
using UnityEngine.InputSystem;
/// <summary>
/// This script shows how to create an Input Action at runtime.
/// </summary>
public class InputActionTest : MonoBehaviour
{
//The input action that will log it's Vector3 value every frame.
[SerializeField]
private InputAction positionInputAction =
new InputAction(binding:"<MagicLeapController>/pointerPosition", expectedControlType: "Vector3");
//The input action that will log every frame when pressed.
[SerializeField]
private InputAction triggerInputAction =
new InputAction(binding: "<XRController>/trigger", expectedControlType: "Button");
private void Start()
{
positionInputAction.Enable();
triggerInputAction.Enable();
triggerInputAction.performed += ActionOnPerformed;
}
private void Update()
{
// Print pointer position to log.
Debug.Log($"Pointer Position: {positionInputAction.ReadValue<Vector3>()}");
}
private void ActionOnPerformed(InputAction.CallbackContext obj)
{
// Print trigger message to log.
Debug.Log("The trigger action was performed.");
}
private void OnDestroy()
{
triggerInputAction.Dispose();
positionInputAction.Dispose();
}
}
See Also: