Skip to main content

Microsoft released the official Hololens SDK a few days ago and I published an introduction to Hololens that went viral. Today, we’ll dive into Hololens Development using the Emulator. I’ll show you how you can build your first Hololens project using Visual Studio and Unity3D.

Prerequisites

Before writing any code, please ensure that your computer meets the minimum requirements have successfully installed the SDK.

Your computer should meet the following specifications:

  • 64-bit Windows 10 Pro, Enterprise, or Education (The Home edition does not support Hyper-V)
  • 64-bit CPU
  • 8 GB of RAM or more
  • In the BIOS, the following features must be supported and enabled:
    • Hardware-assisted virtualization
    • Second Level Address Translation (SLAT)
    • Hardware-based Data Execution Prevention (DEP)
  • GPU (The emulator might work with an unsupported GPU, but will be significantly slower)
    • DirectX 11.0 or later
    • WDDM 1.2 driver or later

Important! You need to have hardware virtualization enabled on your PC. To enable hardware virtualization, follow these instructions (yes, you’ll have to modify your BIOS settings).

Step 0 – Install the SDK

To install the SDK, you need to go through the following steps:

Read my step-by-step guide to installing the Hololens SDK.

Step 1 – Create a New Unity Project

Since everything is set, let’s start doing some cool stuff. So, launch Unity Technical Preview (5.4.0b10) and create a new project. Specify a name and a location. Be sure to select 3D. Then, hit Create project.

Unity is an amazing and easy-to-use game engine with a powerful 3D editor. It was originally developed as a utility for creating games fast, but now it’s used in business apps, too.

Hololens Unity New Project

Unity offers a free and a paid subscription. In the following screenshots, I’m using the paid subscription, however, you do not need the paid plan to develop your Hololens apps. The free version would do the job just fine.

Step 1 – Configure the Main Camera

After you create your project, Unity presents you with an empty 3D view. This is the Unity Editor. Notice the following panels:

  • The Game panel shows how your game will be rendered.
  • The Scene panel shows the elements you have placed within the 3D world. You can interact with this panel and rearrange the visual elements.
  • The Hierarchy panel lists the visual elements of your Scene.
  • The Inspector panel shows the properties of the selected element.

In a holographic app, the Main Camera element is your point of view (your eyes). This is why you need to set its position to zero. Select the Main Camera element and set the X, Y, and Z values of the Position property to zero.

Hololens Unity Step 1

Step 2 – Clear the Background

The Hololens world is, well, the physical world. The sensor lets you project 3D elements within the physical space. As a result, you need to have a transparent background for your app.

To create a transparent background, set the value of the Clear Flags property to Solid Color. Additionally, set the Background property to [0, 0, 0, 0] or #00000000 (Hex and RGBA value for “transparent”).

Hololens Unity Step 2

Step 3 – Add some 3D elements

Now, let’s add our first 3D objects to our scene. Under the Hierarchy panel, select Create → 3D Object → Cube. This will add a cube to the scene. Use the Position, Rotation, and Scale properties to play with the cube. The Z value of the Position property indicates how far the object will be placed. Select a positive number to place the object in front of you. For example, if you set the Z value to “2”, the cube will be positioned 2 meters in front of you.

Hololens Unity Step 3

Step 4 – Deploy

You can add more elements into your scene and create your own virtual 3D world. When you are finished, you’ll need to deploy your app and test it using the Emulator. Unity supports a variety of deployment targets. However, Hololens is only compatible with the Windows Store deployment platform. Windows Store is the newest set of Microsoft APIs. To deploy for Windows Store, click File → Build Settings. The following popup window appears.

Hololens Unity Step 4

Build Settings

  • First, you need to Add Open Scenes. This will ask you to save your current scene and include it in the build.
  • Then, select Windows Store as a build platform.
  • In the SDK option, choose Universal 10.
  • In the UWP Build Type, choose D3D or XAML.
  • Check the Unity C# Projects for debugging.

Player Settings

After specifying the build platform, you need to select the Windows Store capabilities of your app. Click Player Settings. The Inspector panel will show you some options. Select the green Windows Store logo and find the Capabilities list. The following elements should be checked, no matter what:

  • SpatialPerception
  • Microphone
  • InternetClient

SpatialPerception indicates that your app will be capable of using the spatial mapping features. Microphone indicates that your app will be capable of using voice (Cortana) as an input. InternetClient indicates that your app will need network connectivity. Since the emulator is running as a Virtual Machine, you need to check this option, even if your app is not making any use of the Internet. If you do not check this option, you’ll see an error after you deploy your app!

Under the Other Settings list, check the Virtual Reality Supported box. This will let your app run immersively in the 3D space. If left unchecked, the app will run as an ordinary 2D window.

Lastly, click Build.

Unity will ask you to specify a folder for your build. Create a new empty folder anywhere on your computer and click Select Folder. This will generate a Visual Studio solution file.

Hololens Unity Step 5

Step 5 – Launch Visual Studio

It may take a few minutes for Unity to create the Visual Studio solution. After the process is done, open the folder you created and double-click the .sln file to launch Visual Studio.

Hololens Unity Step 6

Step 6 – Run

Visual Studio has packed the binaries and created a project bundle you can later submit to the Windows Store. To run your app, you need to modify the following parameters from the primary command bar:

  • Select Release as your target.
  • Select x86 as your architecture.
  • Select Hololens Emulator as your device.

This is it! Click the green button or select Debug → Start without debugging.

Hololens Unity Step 7

Step 7 – Enjoy!

We did it! Hololens Emulator should launch after a while (it may take up to 15 minutes, though, so please be patient). After the Emulator is launched, you’ll be able to see your cube and interact with it. Try rotating your view using the mouse and arrow keys. Hit the Enter or Space button to select something. The Emulator is like your field-of-view. The tiny circle is where you point.

Hololens Emulator Cube

If you hit the Start key, the Emulator will show you the Hololens Start screen. Feel free to navigate across the apps (arrow keys + Enter). I selected the Edge app. It even has a virtual keyboard!

Hololens Emulator Edge

That’s my website as a hologram! Pretty cool, huh?!

Hololens Emulator Vangos Pterneas

So, this is it for now. During the next few days, we’ll use Unity to create more complex apps and tutorials.

‘Till the next time, stay tuned and share this article with your fellow developers.

Vangos Pterneas

Vangos Pterneas is a software engineer, book author, and award-winning Microsoft Most Valuable Professional (2014-2019). Since 2012, Vangos has been helping Fortune-500 companies and ambitious startups create demanding motion-tracking applications. He's obsessed with analyzing and modeling every aspect of human motion using AI and Maths. Vangos shares his passion by regularly publishing articles and open-source projects to help and inspire fellow developers.

30 Comments

  • Zach says:

    Thanks for the post, doing any more Hololens/Unity posts?

  • Sepp says:

    can i do this on win 7 (64bit) ?????

  • Hi,

    Neat and concise. Great Tutorial.

    Regards

  • Banson says:

    When i try to save my file in any select folders and generate a Visual Studio solution file, the unity has this problem as blow:

    DirectoryNotFoundException: Could not find a part of the path “C:\Program Files (x86)\Windows Kits\10\Platforms\UAP\10.0.10240.0\Platform.xml”.
    System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:292)
    System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share)
    (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
    System.Xml.XmlUrlResolver.GetEntity (System.Uri absoluteUri, System.String role, System.Type ofObjectToReturn)
    Mono.Xml2.XmlTextReader.GetStreamFromUrl (System.String url, System.String& absoluteUriString)
    Mono.Xml2.XmlTextReader..ctor (Boolean dummy, System.Xml.XmlResolver resolver, System.String url, XmlNodeType fragType, System.Xml.XmlParserContext context)
    System.Xml.XmlTextReader..ctor (Boolean dummy, System.Xml.XmlResolver resolver, System.String url, XmlNodeType fragType, System.Xml.XmlParserContext context)
    System.Xml.XmlReader.Create (System.String url, System.Xml.XmlReaderSettings settings, System.Xml.XmlParserContext context)
    System.Xml.XmlReader.Create (System.String url, System.Xml.XmlReaderSettings settings)
    System.Xml.Linq.XDocument.Load (System.String uri, LoadOptions options)
    System.Xml.Linq.XDocument.Load (System.String uri)
    UnityEditor.Scripting.Compilers.UWPReferences.GetPlatform (System.String folder, System.String version) (at C:/buildslave/unity/build/Editor/Mono/Scripting/Compilers/UWPReferences.cs:111)
    UnityEditor.Scripting.Compilers.UWPReferences.GetReferences () (at C:/buildslave/unity/build/Editor/Mono/Scripting/Compilers/UWPReferences.cs:64)
    PostProcessUAP.get_UWPReferences () (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessUAP.cs:21)
    PostProcessUAP.GetAdditionalReferenceAssembliesDirectories () (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessUAP.cs:47)
    PostProcessWinRT.RunSerializationWeaver () (at C:/buildslave/unity/build/PlatformDependent/WinRT/SharedSources/CSharp/PostProcessWinRT.cs:400)
    PostProcessWinRT.Process () (at C:/buildslave/unity/build/PlatformDependent/WinRT/SharedSources/CSharp/PostProcessWinRT.cs:124)
    UnityEditor.WSA.BuildPostprocessor.PostProcess (BuildPostProcessArgs args) (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/ExtensionModule.cs:155)
    UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.BuildReporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:186)
    UnityEditor.HostView:OnGUI()

    Could you please let me know how to fix this issue? Appreciate it.

  • Chris Stockbridge says:

    In the Player settings under Other you also need to select “Virtual Reality Supported”. Some other similar setup guides include this, but yours was the first hit for me, and this was missing, so I spent a while figuring out why the app would build correctly but didn’t seem to deploy to the HoloLens. The symptoms of missing this setting are that there are no errors, but nothing starts on the HoloLens emulator, you just get a screen and the default cursor, but not even the Made With Unity scene opens up.
    It is possible that this wasn’t required when you wrote this post, but it is required to build and run with Unity 5.5

    • Hi Chris. Thank you very much for your comment. If you leave the Virtual Reality Supported box unchecked, the app will run as a 2D windowed application. The blog post has been updated accordingly.

  • ankit says:

    hi can you share some basic things how to make basic applction like the ball can move by hands and add gesture into it. it would be more helpful

  • swathi says:

    Hi,

    Really helpful guide for beginners! It would be helpful if you can help on the below:
    > I have written Integration tests in unity for my holographic project, using Unity test tools. But when I build it as VS solution(like you have said), it throws error. So I had to comment out the places where it mentioned “UnityEditor”.

    Is there a way I can run these integration tests on VS also?

    Thanks in advanace!

  • swathi says:

    Hi,

    Really helpful guide for beginners! It would be helpful if you can help on the below as well:
    > I have written Integration tests in unity for my holographic project, using Unity test tools. But when I build it as VS solution(like you have said), it throws error. So I had to comment out the places where it mentioned “UnityEditor”.

    Is there a way I can run these integration tests on VS also?

    Thanks in advanace!

    • Hello. UNITY_EDITOR is a preprocessor command that specifies that the enclosed code will only be executed on the Unity Editor. The UnityEditor namespace is not necessary when deploying for UWP.

  • Pawn says:

    Hi!
    thanks,this is very helpful!but I get to Step 4 Deploy,click Build button,I get a error: Error building player:Failed to restore NuGet packages. PS:I use unity3d offline.Do you know why
    Regards

  • Pawn says:

    Hi
    This is very helpful
    But when i go to the Step 4 Deploy and click Build button,i get a error:Error building player:Failed to restore NuGet packages.Do you have any idea about this error.PS:I must use unity 3D and vs 2017 offline
    Regards !

  • Vcasa says:

    Hi,
    I have a Mac, not a PC. How can I develop Hololens?

  • Emiliyan Petkov says:

    I have the following errors in Visual Studio after starting the app:

    1>—— Deploy started: Project: HololensWorld, Configuration: Release x86 ——
    1>DEP0100: Please ensure that target device has developer mode enabled. Could not obtain a developer license due to error 800704C7.
    ========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========

    Severity Code Description Project File Line Suppression State
    Error DEP0100: Please ensure that target device has developer mode enabled. Could not obtain a developer license due to error 800704C7. HololensWorld
    Severity Code Description Project File Line Suppression State
    Warning CS0618 ‘ApplicationView.SuppressSystemOverlays.set’ is obsolete: ‘Use the TryEnterFullScreen method and IsFullScreenMode property instead of SuppressSystemOverlays. For more info, see MSDN.’ HololensWorld C:\Users\3D Laptop\Documents\HololensWorld\Build\HololensWorld\App.cs 56 Active

    In the Emulator I see the main menu and no cube.

    • Hi Emiliyan. You need to turn on the Developer Settings of your HoloLens device. This is how to do it (source):

      • Turn on your HoloLens and put on the device.
      • Perform the bloom gesture to launch the main menu.
      • Gaze at the Settings tile and perform the air-tap gesture. Perform a second air tap to place the app in your environment.
      • The Settings app will launch after you place it.
      • Select the Update menu item.
      • Select the For developers menu item.
      • Enable Developer Mode. This will allow you to deploy apps from Visual Studio to your HoloLens.
      • Optional: Scroll down and also enable Device Portal. This will also allow you to connect to the Windows Device Portal on your HoloLens from a web browser.
  • Emiliyan Petkov says:

    Thank you! It works now.

  • Nemo says:

    Hello Vangos ,when i am runing “Start without debugging” I met the error below

    “E:\Holoprojects\GWTest\app1\Unity\Tools\AssemblyConverter.exe” -platform=uap -lock=”E:\Holoprojects\GWTest\app1\GWTest\project.lock.json” -bits=32 -configuration=Release -removeDebuggableAttribute=False -uwpsdk=10.0.17134.0 -path=”.” -path=”D:\Unity\Editor\Data\PlaybackEngines\MetroSupport\Players\UAP\dotnet\x86\Release” “E:\Holoprojects\GWTest\app1\GWTest\Assembly-CSharp.dll” “E:\Holoprojects\GWTest\app1\GWTest\Assembly-CSharp-firstpass.dll” “E:\Holoprojects\GWTest\app1\GWTest\UnityEngine.dll” “E:\Holoprojects\GWTest\app1\GWTest\nunit.framework.dll” “E:\Holoprojects\GWTest\app1\GWTest\UnityEngine.UI.dll” “E:\Holoprojects\GWTest\app1\GWTest\UnityEngine.HoloLens.dll” “E:\Holoprojects\GWTest\app1\GWTest\UnityEngine.Networking.dll” “E:\Holoprojects\GWTest\app1\GWTest\UnityEngine.VR.dll”” exited,code 1。 GWTest E:\Holoprojects\GWTest\app1\GWTest\GWTest.csproj 276

    This has puzzled me a lot .Do you have any idea about this ? Thanks!

  • Laurence says:

    can you still this on a mac? or is it only for PC’s?

Leave a Reply to Vangos Pterneas Cancel Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.