Skip to main content
Version: 20 Mar 2024

Building a Simple App with OpenXR

This document describes how to build a Magic Leap 2 application using Unity.

Prerequisites

Creating a Scene

After setting up your project for the Magic Leap 2 and importing the ML Rig & Inputs package, create a new scene.

  1. Create a new Scene File > New Scene.
  2. Select the "Basic" template from the templates displayed onscreen.
  3. Delete the Main Camera from the scene.
  4. Locate the ML Rig prefab in /Assets/Samples/MagicLeapSDK/<Version>/ML Rig & Inputs and drag it into the scene.
  5. Select the ML Rig and in the Inspector, under XR Origin > Tracking Origin Mode select Device.
  6. Expand the ML Rig fully and select the Main Camera. In the Inspector under the Camera script, find the Clipping Planes values and lower the Near value to 0.25. For more information on the clipping planes, visit the Display Zone Overview guide.
  7. In the Unity menu, go to GameObject > 3D Object > Cube. This will add a cube to the scene.
  8. Click on the Cube in the Hierarchy, then find the Transform properties in the Inspector Panel.
  9. Set the cube's transform properties to:
    • Position at 0, 0, 1
    • Rotation at 0, 65, 0
    • Scale at 0.25, 0.25, 0.25
  10. In Edit > Project Settings > XR Plug-in Management > Open XR > Enabled Interaction Profiles make sure the Magic Leap 2 Controller Interaction Profile is added to the list by clicking the "+" icon on the bottom right and selecting it from the dropdown.
  11. Using the top menu select: File > Save As.

Building to Device

When you are ready to deploy your application to the device, you can use the Build And Run feature of Unity. Make sure you've followed all the setup instructions in the Configure Project Settings guide. Follow the steps below to deploy your application to the device.

  1. Connect and power on the device.
  2. Open the Build Settings, File > Build Settings.
  3. Add your current scene by dragging the scene from the Project panel to the Scenes in Build or clicking on Add Open Scenes.
  4. If you have more than one scene in the list, uncheck all except the one you want to build.
  5. Press Build And Run and select a location and name for the application (.apk)
  6. Wait for Unity to deploy the application.
  7. Put on the device and look around to find the cube.
    • Note: The cube may be behind you depending on the orientation of the device on boot.
You may encounter the following pop-up regarding the Android SDK while building:
"Android SDK is outdated" Pop-up

You may get a pop-up that shows that the Android SDK is outdated when clicking Build. Select Use Highest Installed.