2. Initializing your project and first application
In this first lesson, you'll learn about some of the capabilities the Mixed Reality Toolkit (MRTK) has to offer, start your first application for the HoloLens 2, and deploy it to the device.
- Optimize Unity for HoloLens development.
- Import assets and setup the scene.
- Visualization of the spatial mesh, hand meshes, and the framerate counter.
Create new Unity project
- Start Unity.
- Select New.
- Enter a project name (e.g. "MixedRealityBase").
- Enter a location to save your project.
- Make sure the project is set to 3D.
- Click Create Project.
Configure the Unity project for Windows Mixed Reality
- Open the Build Settings window by going to File>Build Settings.
- Switch to Universal Windows Platform by selecting Universal Windows Platform. Click the Switch Platform button to switch platforms. Applications running on HoloLens 2 are required to be Universal Windows Platform (UWP) compatible.
- Enable virtual reality by clicking on Player Settings in the Build Window, and enable the Virtual Reality Supported checkbox under XR Settings from the inspector panel, as shown in the image below. Note that you might need to drag the Build Settings window out of the way in order to see the inspector panel. The Virtual Reality Supported checkbox also applies to Mixed Reality and Augmented Reality headsets because it refers to the enabling of stereoscopic vision (rendering different images for each eye.)
- From the same inspector panel, ensure that the Spatial Perception checkbox in the capabilities section is enabled under Publishing Settings. Spatial Perception allows us to visualize the spatial mapping mesh on a mixed reality device, such as HoloLens 2. Publishing Settings are found in the inspector panel, above XR Settings and under Other Settings.
NOTE: While not used in this section, some other common capabilities you might want to enable include the microphone for voice commands, and InternetClient for connecting to services requiring a network connection.
Import the Mixed Reality Toolkit
Download the Mixed Reality Toolkit Unity package, and save it to a folder on your PC.
Import the Mixed Reality Toolkit package by clicking on Assets>Import>Custom Package. Find the Mixed Reality Toolkit package downloaded in Step 1 and open it to begin the importing process. Please allow a few minutes for the importing process.
In the next pop-up window, click Import to begin importing the Mixed Reality Toolkit. Ensure all items are checked as shown in the image. If you see a pop-up dialog box asking to apply the Mixed Reality Toolkit default settings, click Apply.
Configure the Mixed Reality Toolkit
- Configure the MRTK by selecting Mixed Reality Toolkit > Configure from the menu bar. If you don't see this menu item after importing the mixed reality toolkit, please restart Unity.
Note: You may see a pop-up dialog box asking to select a profile for the Mixed Reality Toolkit. If so, select Ok, and choose the profile named "DefaultMixedRealityToolkitConfigurationProfile."
- Your scene will have several new items and modifications in it from the MRTK. Save your scene under a different name by clicking File>Save As, and give your scene a name, such as BaseScene. Keep your scene organized by saving it to the Scenes folder in your project’s Assets folder.
Build your application to your device
If you closed the Build Settings window from the previous sections, open the Build Settings window again by going to File>Build Settings.
Ensure the scene you want to try is in the Scenes in Build list by clicking on the Add Open Scenes button.
Press the Build button to begin the build process.
Create and name a new folder for your application. In the image below, a folder with the name App was created to contain the application. Click Select Folder to begin building to the newly created folder. After the build has completed, you can close the Build Settings window in Unity.
NOTE: If the build fails, try building again or restarting Unity and building again. If you see an error, such as "Error: CS0246 = The type or namespace name “XX” could not be found (are you missing a using directive or an assembly reference?). If so, then you might need to install Windows 10 SDK (10.0.18362.0)
- After the build is completed, open the newly created folder containing your newly built application files. Double click on the MixedRealityBase.sln solution, or the corresponding name, if you used an alternative name for your project, to open the solution file in Visual Studio.
Note: Be sure to open the newly created folder (i.e., the App folder, if following the naming conventions from the previous steps), as there will be a similarly named .sln file outside of that folder that is not to be confused with the .sln file inside the build folder.
Note: If Visual Studio asks you to install new components, please take a moment to ensure that all prerequisite components are installed as specified in the "Install the Tools" page
Connect your HoloLens 2 into your PC. While these instructions assume you will be deploying a test with a HoloLens 2 device, you might also choose to deploy to the HoloLens 2 emulator or choose to create an app package for sideloading
Before building to your device, ensure that the device is in Developer Mode. If this is your first time deploying to the HoloLens 2, Visual Studio might ask you to pair your HoloLens 2 with a PIN. Please follow these instructions if you need to enable developer mode or pair with Visual Studio.
Configure Visual Studio for building to your HoloLens 2 by selecting the Release configuration and the ARM architecture.
The final step is to build to your device by selecting Debug>Start without debugging. Selecting Start without Debugging causes the application to immediately start on your device upon a successful build, but without debugging information appearing in Visual Studio. This also means that you can disconnect your USB cable while your application is running on your HoloLens 2 without stopping the application. You might also select Build>Deploy Solution to deploy to your device without having the application automatically start.
You have now deployed your first HoloLens 2 application. As you walk around, you should see a spatial mesh covering all the surfaces that have been perceived by the HoloLens 2. Additionally, you should see indicators on your hands and fingers for hand tracking and a frame rate counter for keeping an eye on application performance. These are just a few of the foundational pieces, included out of the box, with the Mixed Reality Toolkit. In the lessons to come, you start adding more content and interactivity to your scene so that you can fully explore the capabilities of HoloLens 2 and the Mixed Reality Toolkit.
Note: You will cover how to toggle the frame rate counter using a voice command in Lesson 5