HoloLens Tutorial – Spatial Mapping

Last Updated: Apr 18, 2017

Tutorial Accomplishments

  1. Spatial Mapping Observer and Manager
  2. Next Steps after Spatial Mapping


After the first two sections of this tutorial series our project has source control setup, and a basic scene that builds and successfully deploys to either the Emulator or a HoloLens device. Your project should look something like this:

We have the HoloToolkit imported into our project and a scene created.  We also have two GameObjects in the scene, the Directional Light creates light for our scene and the Main Camera represents the user in the world.


Spatial Mapping Observer and Manager

Start by creating a new Empty GameObject in the Hierarchy, rename it to “Spatial Mapping”. This gameobject will hold all the scripts related to spatial mapping. Select the Spatial Mapping node in the Hierarchy and select Add Component. Add “Spatial Mapping Manager”. The Inspector should now show the following for your Spatial Mapping node in the Hierarchy:


You will notice that a “Spatial Mapping Observer” script was automatically added. This is added because of the RequireComponent attribute on the “Spatial Mapping Manager” script.


This tells Unity that the observer script is required by the manager script and Unity will add it automatically for you.  The HoloToolkit uses this attribute to help the developer not miss dependencies.

Check the “Draw Visual Meshes” checkbox on the Spatial Mapping Manager. This tells the HoloToolkit to draw the Spatial Map so that the user can see the mapping as it is happening. Next Select the Surface Material for the manager and select “Wireframe” from the list of materials. The wireframe material is the standard spatial mapping material provided with the HoloToolKit. From the File menu, Save your Scene. Open the build settings for this project and Click the Player Settings button. On the Windows Store Build Settings select Publishing Settings and add the “SpatialPerception” capability.  This permission causes Unity to request access to the SpatialPerception hardware of the HoloLens, which is required for Spatial Mapping and almost all HoloLens specific functionality.

Build the project.  Open the build results in Visual Studio and build to the HoloLens.  On the HoloLens you should now see the Spatial Map of the room you are in and/or emulating, it should look similar to this:



What comes next?

If we were only using spatial mapping the next section would be focused on providing the user an interface to understand the quality of the spatial map and finish spatial mapping which would start the actual application. I did not do that for this application because I used Spatial Understanding for this application.  The next section will layer Spatial Understanding on top of spatial mapping and build a user interface to allow the user to finish mapping the room. Most of these concepts are very similar. If you would like to see a specific tutorial on how to do this with only Spatial Mapping let me know!

Tutorial Index

  Versions: Unity 2017.1.0p5 | MixedRealityToolkit-Unity v1.2017.1.0Visual Studio 2017 15.3.2
Unity 3D Project Creation How to create a HoloLens project in Unity 3D
Source Control Configure git for HoloLens / Unity work
Spatial Mapping How to spatial map a Room
Object Surface Observer Set up fake spatial map data for the Unity editor
TagAlongs and Billboarding   Tag along instructions to the user to force text on screen
Spatial Understanding Add spatial understanding to get play space detail
Finalizing Spatial Understanding Complete Spatial Understanding and Input Manager
Object Placement and Scaling Find valid locations for holograms in the play space
Hologram Management Manage the holograms you want to place in the world
Cursor and Voice Add a cursor and voice commands
Occlusion Add occlusion with the real world to your scene
Colliders and Rigidbodys Add Colliders and RigidBodys to your holograms

One thought on “HoloLens Tutorial – Spatial Mapping

  • Posted on March 14, 2017 at 11:56 am

    Note that if you have already exported your Unity project to a Visual Studio solution, you will need to either export to a new folder or manually set this capability in the AppxManifest in Visual Studio.


Leave a Reply