[!IMPORTANT] The Mixed Reality Academy tutorials were designed with HoloLens (1st gen), Unity 2017, and Mixed Reality Immersive Headsets in mind. As such, we feel it is important to leave these tutorials in place for developers who are still looking for guidance in developing for those devices. These tutorials will not be updated with the latest toolsets or interactions being used for HoloLens 2 and may not be compatible with newer versions of Unity. They will be maintained to continue working on the supported devices. A new series of tutorials has been posted for HoloLens 2.
This tutorial will walk you through creating a basic mixed reality app built with Unity.
Course | HoloLens | Immersive headsets |
---|---|---|
MR Basics 100: Getting started with Unity | ✔️ | ✔️ |
[!VIDEO https://www.youtube.com/embed/2L5IFO0hnYA]
To build an app with Unity, you first need to create a project. This project is organized into a few folders, the most important of which is your Assets folder. This is the folder that holds all assets you import from digital content creation tools such as Maya, Max Cinema 4D or Photoshop, all code you create with Visual Studio or your favorite code editor, and any number of content files that Unity creates as you compose scenes, animations and other Unity asset types in the editor.
To build and deploy UWP apps, Unity can export the project as a Visual Studio solution that will contain all necessary asset and code files.
Congrats, you are all setup to get started with your mixed reality customizations now.
[!VIDEO https://www.youtube.com/embed/eP1ZwB4wSNA]
The Unity Main Camera handles head tracking and stereoscopic rendering. There are a few changes to make to the Main Camera to use it with mixed reality.
First, it will be easier to lay out your app if you imagine the starting position of the user as (X: 0, Y: 0, Z: 0). Since the Main Camera is tracking movement of the user’s head, the starting position of the user can be set by setting the starting position of the Main Camera.
Second, the default Camera background needs some thought.
For HoloLens applications, the real world should appear behind everything the camera renders, not a Skybox texture.
For mixed reality applications targeted to immersive headsets, we can use the default Skybox texture that Unity provides.
Third, let us consider the near clip plane in Unity and prevent objects from being rendered too close to the users eyes as a user approaches an object or an object approaches a user.
For HoloLens applications, the near clip plane can be set to the HoloLens recommended 0.85 meters.
For mixed reality applications targeted to immersive headsets, we can use the default setting that Unity provides.
Finally, let us save our progress so far. To save the scene changes, select File > Save Scene As, name the scene Main, and select Save.
[!VIDEO https://www.youtube.com/embed/ItRoiXccC0g]
In this chapter, we will set some Unity project settings that help us target the Windows Holographic SDK for development. We will also set some quality settings for our application. Finally, we will ensure our build targets are set to Universal Windows Platform.
Unity quality settings for HoloLens
Since maintaining high framerate on HoloLens is so important, we want the quality settings tuned for fastest performance. For more detailed performance information, Performance recommendations for Unity.
For mixed reality applications targeted to occluded displays, you can leave the quality settings to its default values.
Target Windows Holographic SDK
We need to let Unity know that the app we are trying to export should create an immersive view instead of a 2D view. We do this by enabling Virtual Reality support on Unity targeting the Windows 10 SDK.
[!NOTE] If you do not see the Universal Windows Platform icon, double check to make sure you selected Universal Windows Platform Build Support during installation. If not, you may need to reinstall Unity with the correct Windows installation.
Awesome job on getting all the project settings applied. Next, let us add a hologram!
[!VIDEO https://www.youtube.com/embed/qKcK1Yuj-HQ]
Creating a cube in your Unity project is just like creating any other object in Unity. Placing a cube in front of the user is easy because Unity’s coordinate system is mapped to the real world - where one meter in Unity is approximately one meter in the real world.
[!VIDEO https://www.youtube.com/embed/vmCfiIdRb6Q]
Now that we have created our cube, it is time to do a quick check in device. You can do this directly from within the Unity editor.
You will now be able to see the cube in device and in the editor. You can pause, inspect objects, and debug just like you are running an app in the editor, because that’s essentially what’s happening, but with video, audio, and device input transmitted back and forth across the network between the host machine and the device.
You will now be able to see the cube rendering in your mixed reality headset and in the editor.
[!VIDEO https://www.youtube.com/embed/USSu8yHUdbk]
We are now ready to compile our project to Visual Studio and deploy to our target device.
Finally, we will compile the exported Visual Studio solution, deploy it, and try it out on the device.
The instructions differ for deploying to a device versus the emulator. Follow the instructions that match your setup.
For HoloLens, If this is the first time deploying to your device, you will need to pair using Visual Studio.
Ensure you device is plugged in via the USB cable.
Now that your app is deployed, try moving all around the cube and observe that it stays in the world in front of you.