Introducing Magic Leap With Unity3D


Magic leap is adding another dimension to computing where digital respects the physical. They work together to make life much better. Magic Leap One is built for creators who want to change how we experience the world. It drags digital world into the real world. Simply it gives a mixed reality experience to us. Before we take step forward into mixed reality, we have to be clear with these three terms : Virtual reality, Augmented reality and Mixed reality.

What is the difference between Virtual Reality, Augmented Reality and Mixed Reality?

To cut a long story short, here’s the difference between virtual, augmented, and mixed reality technologies:

  • Virtual reality (VR) immerses users in a fully artificial digital environment.
  • Augmented reality (AR) overlays virtual objects on the real-world environment.
  • Mixed reality (MR) not just overlays but interacts with your real world. It anchors virtual objects in the real world.

Begin exploring

To get started you need to download the Unity engine tool for Magic Leap Technical Preview and Magic Leap Lumin SDK.

Lumin Sdk :

Unity Technical Preview :

Magic Leap Setup

Step 1 : Install required packages from Magic Leap Package Manager

Download and install the latest Magic Leap Package Manager. Lumin SDK has a lot of magic stuff and tools to help create experiences and apps. We don’t have to cover all that now, so, let’s continue with all this marked packages.


Step 2 : Generate, decorate and experience virtual rooms

With the help of Magic Leap Simulator, You can see your quick changes to Unity Editor without deploying to Magic Leap Headset Devise. This simulator covers the major Lumin SDK features. After creating your own room using Virtual Room Generator, load your room in Magic Leap Simulator. Here you can fully explore your room and test it.

In the Magic Leap Remote – Simulator Mode window

  1. Click Start Simulator
  2. In the Simulator window, Click the ☰ menu (the one in the Mini Map window) – Click Load Virtual Room
  3. Navigate to VirtualDevice\data\VirtualRooms\ExampleRooms in your Lumin SDK installation folder.
  4. Select an example room of choice
    leap-setupYou can also generate your custom room with Virtual Room Generatorleap-setup

Unity Setup

Magic Leap with Unity

Hope you are ready with Unity 2018.1.0b8 as it’s essentially required for magic leap demonstration.

Let’s get a new Unity project setup using the Magic Leap template. Templates are a new feature in Unity’s project launcher.

  1. Open the Unity 2018.1.0b8-MLTP1
  2. Create new project
  3. Set project name and location
  4. [New!] Template: Magic Leap
  5. Select Create project


Project Setup


  1. GameObject > 3D Object > Cube

Build Settings

  1. File > Build Settings
  2. Under the Platform section
    1. Select Lumin OS
    2. Click the Switch Platform button below
    3. Set the Lumin SDK Location path. For example, /User/(User Name)/MagicLeap/mlsdk/v0.11.1
  3. Close the Build Settings windowbuild-settings


Let’s enable Zero Iteration.

  1. Click the Magic Leap menu at the top of Unity
  2. Click Enable Zero Iteration
  3. An Editor Restart Required popup will appear
  4. Click Restart
  5. Unity will now restart in OpenGL mode

Let’s zap our cube over to the Simulator window.

  1. Unity click Play to enter Play Mode
  2. Our cube now appears in the Eye View window pane of the Simulator
  3. Use WASD and mouse controls to move around and view the cube from different angles


Remember: The simulator should always be started before pressing Play

As you can see, cube is in the real world but it is not still interacting with real world (here virtual world). You can not drag your cube behind any sofa or under the table or anywhere you want. It will still look like AR. To interact with real world you also need mesh real environment in your Unity. If it is possible then it’s not big deal to put your cube wherever you want in the real world. Yes, Magic Leap provides this functionality to import meshes of real world in Unity. And here we go to drag meshes in Unity.

Meshing in Unity

Meshing is a feature of World Reconstruction that detects real world surfaces and constructs a virtual mesh around those objects.

  1. Import the Magic Leap Unity Package (Path : /Users/UserName/MagicLeap/tools/unity/v0.11.1).package
  2. Create an empty GameObject, name it MLSpatialMapper.
  3. Attach an MLSpatialMapper Script (AR->Magic Leap->Spatial Mapper) to the MLSpatialMapper GameObject.
  4. Create the mesh prefab.
    1. Select MLSpatialMapper and create a child GameObject, named Original.
    2. This object acts as a template for creating the meshes. At runtime, MLSpatialMapper will create meshes and set them in the Mesh field of the MeshFilter attached to the Original GameObject.
    3. Disable the Original GameObject.
    4. Remove any transform offsets.
    5. Add a Mesh Renderer component.
    6. Add a Mesh Filter component
    7. Add a Mesh Collider component
  5. Launch the application using the Magic Leap Remote(see the Prerequisites). The mesh should appear shaded pink (since no materials have yet been applied).
  6. Now let’s apply materials to the mesh.
    1. Create a new material, and name it Wireframe. Assign the Wireframe shader (VR->SpatialMapping->Wireframe).wireframe
    2. Create a new material, and name it Occlusion. Assign the Occlusion shader (VR->SpatialMapping->Occlusion).occlusion
    3. Assign both materials to the Original GameObject’s MeshRenderer.
  7. Create one Cube and add Rigidbody component to it.
  8. Launch Simulator and click on play button in Unity.

You will see meshes are derived in scene view in Unity. And your Cube is now interacting with real world. You can put your cube wherever you want in environment.

Now your game characters can come in real world and they can do whatever with respect to real world. Here you can see one demo game in which player is playing with ball in real environment.


It was combined efforts of Damini Hajare, Bhavesh Savaliya and Vaibhav Vasoya.


Damini Hajare

I am Damini Hajare, enthusiastic Game developer at Yudiz Solution Pvt Ltd- a mobile app development company. I am passionate Game Developer. My aim is to making fun loving and addictive games.

Comments are closed.