This Unity tutorial will take you through step-by-step so you can start developing for HoloLens. Once your device is ready in developer mode, you can start building your own augmented reality application in Unity.
Setting Up and Testing on a HoloLens Emulator
If you don’t have a HoloLens, you’ll want to download an emulator so you can test your application as you build.
The HoloLens emulator runs through Visual Studio. You can download the emulator here, and Visual Studio here. Note that the emulator will not work on Windows 10 Home OS. You’ll need Windows 10 Pro, Enterprise, or Education. You can check your system OS in your Settings window under ‘About’.
If you don’t want to setup the emulator, you can skip ahead to setting up a Unity project for HoloLens.
To setup your HoloLens Emulator:
It’s possible to develop for the HoloLens without actually owning one. But, you’ll need to download the emulator for testing purposes. Here’s how:
- Head into your Control Panel, and navigate to Programs, then Programs and Features. Click on the link on the left-hand side labeled Turn Windows Features On or Off. In the pop-up window, enable Hyper-V.
- Make sure your Graphics Card is up to date. You can update your driver using Device Manager. Navigate to Start, to Device manager, then to Display Adapters. Select your Graphics Card, and the option to Update Driver.
- We’ll want to ensure the Windows 10 Fall Creator Update is installed. It should have occurred automatically in your normal OS updates. To install manually follow this link and the instructions on the screen.
- Confirm that you have the latest version of Visual Studio installed. You can find the latest version here.
- Install the Windows 10 SDK at this link here.
- Install or Update to the latest version of Unity (Unity 2017.4 or above). You’ll want to confirm that you have the following components selected: Windows Store .NET Scripting Backend; Windows Store IL2CPP Scripting Backend; and Vuforia Augmented Reality Support.
- Download the HoloLens Emulator here.
- Lastly, download the Windows Mixed Reality Toolkit from the GitHub repository here. As you might know, you’ll be downloading a lot of SDKs and Toolkits throughout the development process so it’s a good idea to have a special folder where you’ll save and store them.
Setting up Unity to Start Developing for HoloLens
After finishing download the programs you need to run your emulator, you’re ready to get started in Unity.
- Open Unity and create a new 3D project
- Navigate to File and into your Build Settings and confirm the settings are as follows (pictured below): Your platform is set to Universal Windows Platform, with your Target Device set to HoloLens, Build Type as D3D, SDK and Visual Studio set to Latest Installed, and that you’re set to Build and Run on Local Machine. Once you’re set, select Switch Platform.
- Select Player Settings and navigate to XR Settings, then add your Mixed Reality SDK
- Head back to Player Settings and navigate to Other Settings, and confirm your Configuration is as pictured below:
- Navigate to Publishing Settings and then to Capabilities. We’ll want to enable InternetClient, Microphone, and SpatialPerception.
- If you haven’t already, download the Windows Mixed Reality Toolkit here.
- We’ll bring the HoloToolkit folder from the Mixed Reality Toolkit into Unity. First, we’ll unzip the Windows Mixed Reality Toolkit. Open your Unity Assets folder and drag the HoloToolkit folder into the Project’s Assets folder. Once linked, the Mixed Reality Tab should appear on the top of your Unity menu bar alongside File, Edit, GameObject, etc.
- Now navigate to Mixed Reality Toolkit menu to Configure and Mixed Reality Project Settings. Confirm you have the following checkmarked, then select apply.
- You’re doing great! We’ll head back into Unity’s main window, and delete the default camera from your hierarchy tab. Along the bottom window navigate to HoloToolkit > Input > Prefabs and drag your HoloLensCamera into your hierarchy tab. Save your scene!
- Lastly we’ll navigate to File and to Build Settings, select Open Scenes, and Build into a separate folder.
You’re now ready to start developing in Unity! But before hitting play, let’s confirm the HoloLens emulator is working with your Unity project. If you’re deploying your app onto an actual HoloLens device, we have instructions for you here.
|Download our 10-week VR Development with Unity Course Syllabus|
Deploying your app onto the HoloLens Emulator for testing
To make sure the emulator is working, let’s add a 3D Object into your scene. You can do this in Unity by right-clicking on the Hierarchy tab and selecting a 3D Object, let’s say a 3D rectangle. Then save and close Unity.
- Open your .sln project into Visual Studio. Set the Debug settings as shown below. If you have the emulator setup correctly, you should be able to see the option in the dropdown menu on the right.
- Navigate to the Debug menu and select Start Debugging. This should bring up the emulator.
- Users navigate HoloLens applications using hand gestures. In an emulator, we use keys to simulate these gestures. The F2 key acts as the “Bloom” gesture. The enter key works as the “Air Tap” gesture. You can move around the computer mouse to emulate the “Gaze” interaction. Using these keys, open your application and it should load similar to what’s below:
Deploying your app onto the HoloLens for testing
If you are testing your application on an actual HoloLens instead of an emulator, there’s a few extra steps to ensure your HoloLens is setup in Developer Mode.
- Enable Developer Mode on your desktop by navigating to your Settings, selecting Updates and Security, and clicking For Developers on the menu to your left. Confirm Developer Mode is on, and enable remote diagnostics and authentication, as seen below:
- Next, connect your HoloLens to your computer through its USB cord. When you start your HoloLens, you’ll want to re-open your desktop’s Settings window, head into Updates and Security, For Developers, and turn Developer Mode ON for your HoloLens.
- Now we’ll pair your HoloLens with your computer. Your computer will ask for a Pin that you’ll generate on your HoloLens. Scroll down to Device Portal and click Pair to Generate Pin. Activate bluetooth on your HoloLens.
- Pair HoloLens with your computer through your Settings window, to Devices, and selecting Add Bluetooth or Other Device. This is when you’ll need to input your HoloLens pin.
- You’re almost there! After the pairing completes, open the project as .sln in Visual Studio. Configure the Debug settings as shown below, then navigate to the Debug menu and Start Debugging.
The application should now show up on your HoloLens. Once you do this, you can even start your application on HoloLens directly by running on Unity.
Help! HoloLens Troubleshooting
Don’t panic! In some cases, you may need to select Release instead of Debug. If Start Debugging gives an error saying you need to deploy the app first, navigate to Build in the menu bar and deploy from there instead. Other deployment errors are often fixed by deleting your .sln file and rebuilding from within Unity, but hopefully it doesn’t come to that!
Whether you’re building for augmented or mixed reality, Microsoft HoloLens is a great device to work with. Now that you’re setup, you’re ready to get building. Check out our programming guides for further resources.
Tired of learning on your own, download our syllabus and see how we can help you build a working prototype in just 10-weeks through small classes, live online training, and one-on-one sessions with instructors.
- Go to Control Panel > Programs > Programs and Features > Turn Windows Features On or Off, then enable Hyper-V
- Update Graphics Card
- Install Windows 10 Fall Creator update here
- Install/update Visual Studio here
- Install Windows 10 SDK here
- Install/update Unity and confirm you have selected:
- Windows Store .NET Scripting Backend;
- Windows Store IL2CPP Scripting Backend; and
- Vuforia Augmented Reality Support
- Download HoloLens emulator here
- Download Windows Mixed Reality Toolkit from GitHub here
Basic Unity Setup for HoloLens:
- Startup Unity and create new 3D project
- Go to File > Build Settings and change settings to below, select Switch Platform
- Universal Windows Platform
- Target Device set to HoloLens
- Build Type set to D3D
- SDK set to Latest installed
- Visual Studio Version set to Latest installed
- Build and Run on Local Machine
- Go to Player Settings > XR Settings and add Mixed Reality SDK
- Go to Player Settings > Other Settings and change Configuration to:
- Scripting Runtime Version set to Stable (.NET3.5 Equivalent)
- Scripting Backend set to .NET
- API Compatibility Level set to .NET
- Accelerometer Frequency set to 60 Hz
- Go to Publishing Settings > Capabilities and have checkmarked:
- Download Windows Mixed Reality Toolkit here if not already downloaded
- Unzip Mixed Reality Toolkit; import HoloToolkit into Project’s Asset folder; Mixed Reality Toolkit will now appear in Unity menu bar
- In Unity, navigate to Mixed Reality Toolkit menu bar > Configure > Mixed Reality Settings and select:
- Target Windows Universal UWP
- Enable XR
- Build for Direct3D
- Use Toolkit-specific InputManager axes
- Enable .NET scripting backend
- Delete default camera in hierarchy tab; add HoloLensCamera into hierarchy tab from HoloToolkit prefabs folder
- Save scene; go to Build Settings > Add Open Scenes > Build into a separate folder
Deploying and Testing App on Emulator:
- Open .sln project in Visual Studio. Set Debug settings to x86 and HoloLens emulator in drop down menu.
- Go to Debug > Start Debugging to bring up emulator
- F2 key acts as “Bloom” gesture; Enter key acts as “Air Tap” gesture; mouse acts as “Gaze” interaction. Use these keys to open app.
Deploying and Testing App on HoloLens:
- Enable Developer Mode on Computer:
- Navigate to Settings > Updates and Security > For Developers, and enable Developer Mode, remote diagnostics, and authentication
- Connect HoloLens to Computer
- Once HoloLens is connected, on computer go to Settings > Updates and Security > Developer Mode > For Developers > Turn Developer Mode ON
- Pair HoloLens to Computer:
- Navigate to Device Portal > Pair > Generate Pin
- Activate bluetooth with HoloLens at Settings > Devices
- Pair HoloLens to Computer via Settings > Devices > Add Bluetooth or Other Device. Input HoloLens Pin when prompted
- Open project .sln in Visual Studio. Set Debug settings to x86 and Device in drop down menu
HoloLens Deployment Troubleshooting:
- May need to select Release instead of Debug
- If Start Debugging gives error saying you need to deploy app first, go to Build menu and deploy from there
- Delete .sln file and rebuild in Unity