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.
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.
Input Events
Input actions contain using 3 callbacks, started, performed, and canceled. While the order and how the events are triggered depend on the type of the action, the table below shows the default behavior.
Type | Description |
---|---|
InputAction.started | When a control is actuated (i.e. moving away from its resting position) |
InputAction.performed | Called right after started, and continues to be called while the action is being performed. |
InputAction.canceled | When the control moves back to its default value (i.e. resting position) |
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: