Building a Simple App
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, create a scene for our app.
- Create a new Scene File > New Scene.
- Select "Basic (URP)" from the four templates displayed onscreen.
- Delete the Main Camera from the scene.
- Locate the XR Rig prefab in
Packages/Magic Leap SDK/Runtime/Tools/Prefabs
and drag it into the scene. - In the Unity menu, go to GameObject > 3D Object > Cube. This will add a cube to the scene.
- Click on the Cube in the Hierarchy, then find the Transform properties in the Inspector Panel.
- 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
- Using the top menu select: File > Save As.
Testing using Magic Leap App Simulator
Using the Magic Leap App Simulator, you can test some of your application's features without having to build and deploy it to your device. See the Unity Application Simulator section for details on how to configure your Unity settings to run the Application Simulator.
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 Unity Settings guide. Follow the steps below to deploy your application to the device.
- Connect and power on the device.
- Open the Build Settings, File > Build Settings.
- Add your current scene by dragging the scene from the Project panel to the Scenes in Build or clicking on Add Open Scenes.
- If you have more than one scene in the list, uncheck all except the one you want to build.
- Press Build And Run and select a location and name for the application (.apk)
- Wait for Unity to deploy the application.
- 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:
- Windows
- MacOS
You may get a pop-up that shows that the Android SDK is outdated when clicking Build. Select Use Highest Installed.
![](/img/unity/unity-android-sdk-is-outdated-windows.png)
You may get a pop-up that shows that the Android SDK is outdated when clicking Build. Select Use Highest Installed.
![](/img/unity/unity-android-sdk-is-outdated-macos.png)
Next Steps
Unity Examples Project
After successfully creating a new application, check out the pre-configured Magic Leap Unity Examples Project to see some of Magic Leap's unique platform features.
Magic Leap App Simulator
The Magic Leap App Simulator can be used to test applications much faster, without deploying them to the physical device. See our Magic Leap App Simulator for Unity section to learn how to configure your unity settings to run applications in the Simulator.
MRTK for Magic Leap
Developers can quickly build or upgrade applications using Magic Leap's MRTK support package. See the MRTK for Magic Leap guide to learn how to use the MRTK for Magic Leap package in your project.