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:
- Enable Virtualization
- Enable Hyper-V
- Install Visual Studio 2015 Update 2
- Install the emulator
- Install Unity Technical Preview
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.
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.
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”).
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.
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.
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.
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.
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.
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.
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!
That’s my website as a hologram! Pretty cool, huh?!
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.
Thanks for the post, doing any more Hololens/Unity posts?
Hi Zach. Yes, we have some cool tutorials coming. Check this:
https://www.facebook.com/pterneas/videos/vb.1346760039/10210161280932291/?type=2&theater
I am going to publish the source code, too.
Awesome keep up the good work comming 🙂
can i do this on win 7 (64bit) ?????
Hi Sepp. The HoloLens SDK is only available for Windows 10. HoloLens runs Windows 10, too.
Hi,
Neat and concise. Great Tutorial.
Regards
Thank you very much!
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.
Hello Banson. Have you installed the Windows 10 UWP Tools?
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.
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
I have that same question. How would one be abe to take user input to create a game that works through the HoloLens. Would it involve C# scripting?
You can check this tutorial: A Pokemon-Go clone for HoloLens
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!
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.
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
Hi Pawn. To restore the NuGet packages, you need an active Internet connection.
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 !
Hi,
I have a Mac, not a PC. How can I develop Hololens?
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):
Thank you! It works now.
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!
I am using unity5.6.0 bit32. I have used unity2017 bit 64.That works well. But I need to use a 32bit one and meet this problem.
Hi Nemo. Microsoft is now recommending Unity 2017.4. This is why Unity 32bit will likely not work any longer.
can you still this on a mac? or is it only for PC’s?