Skip to main content
Version: 14 Oct 2024

Example Project

Magic Leap Unity (OpenXR) Examples

The Magic Leap Unity Examples package version 2.0.0 or newer provides example scenes utilizing OpenXR features in Unity. These examples can be downloaded via Magic Leap Hub's Package Manager and then built for Magic Leap using the Unity Editor.

Prerequisites

  • ML OS 1.5 or higher
  • Magic Leap Hub 3 (ML Hub3)
  • Unity 2022.3.11f1

Downloading the Examples Project

This section will walk you through downloading the Magic Leap Examples Unity project using the Package Manager inside ML Hub 3.

Open The Package Manager

To access the Package manager in ML Hub 3

  1. Open ML Hub 3.
ML Hub 3 Dashboard
  1. Select Packages from the left sidebar.
Package Manager

Download The Package

To download the Unity Magic Leap Examples Project as an individual package

  1. Select the OpenXR Samples item from the list.
  2. Lastly, click Install button from the details section.
ML Hub 3 OpenXR Samples Package option outlined

Open the Example Project

Once the project has been downloaded, open the project using the Unity Hub.

  1. Open the Unity Hub application
  2. Click Open in the upper right corner of the home page and navigate to the MagicLeap_Examples project inside your MagicLeap/tools/unity/<SDK_VERSION>/ directory.
    • Example: %USERPROFILE%\MagicLeap\tools\unity\<Version>\MagicLeap_Examples
  3. Make sure the project is opened using the Magic Leap 2 compatible editor version that you installed in Getting Started.
  4. Select the MagicLeap_Examples folder and click Open.

Building to Device

  1. Open the build menu under File > Build Settings and select any or all of the scenes you wish to demo. The scenes will allow you to switch between examples from within the app, so feel free to include all of the examples.
  2. Make sure your build target is set to Android.
  3. Turn on your Magic Leap 2 and connect it to your computer via USB or Wifi, then select the device under Run Device.
  4. Click Build and Run to deploy the Magic Leap 2 Examples on your headset.

Examples Scenes

Magic Leap provides seven examples:

  • Hello, Cube
  • Control
  • EyeGaze
  • Hands
  • Planes
  • GlobalDimmer
  • SegmentedDimmer

Hello, Cube

This is the example that is loaded when you open all the OpenXR scenes for Unity on your Magic Leap 2 headset. It is a red cube that the window floats over.

Control

This example demonstrates and prescribes preferred methods for receiving input from the Control controller. When the controller is connected, the pointer follows the physical controller with 6dof and stats about the controller show up in the Status tab of the UI. When the controller is disconnected, the UI mapped to this controller displays the status as disconnected.

EyeGaze

Use the Gaze Interaction profile to track your eye gaze around the scene. Text that says Target appears above one of the spheres if you look at it.

note

You can lock or minimize the instructions window to keep it from blocking your view.

To use this feature, you must grant the following permission:

  • com.magicleap.permission.EYE_TRACKING

You are prompted to grant the permission when you open this scene.

Hands

This example uses the Hand Interaction Profile to map OpenXR hand gestures to Unity Input Actions, as well as the Hand Tracking Subsystem from Unity's XR Hands package to read hand, bone, and joint data.

Sample assets have been imported from Unity's XR Hands package.

This example reads Pinch actions and leaves markers where a pinch occurred.

Planes

This example scene detects surfaces and displays the planes in your environment as you look around.

Planes can be vertical or horizontal, and the scene makes surfaces different colors according to both untagged and semantically tagged planes (floors - green, walls - red, ceiling - blue, tables - yellow).

Grey planes have no semantic classification.

Mandatory permission required by this feature: com.magicleap.permission.SPATIAL_MAPPING

GlobalDimmer

This example uses the Global Dimmer to dim the entire environment around you. You can toggle the Global Dimmer on or off, or adjust the dimming level.

SegmentedDimmer

This example demonstrates the effects of the Segmented Dimmer via AlphaBlend mode. For the Segmented Dimmer to be visible in your scene, you must be using an XrEnvironmentBlendMode set to XrEnvironmentBlendMode.Additive, and you must have enabled Segmented Dimming in your system's settings.

note

XrEnvironmentBlendMode.Opaque is currently not supported on Magic Leap.