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

3 thoughts 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.

  • Posted on April 19, 2018 at 11:40 am

    Hello, thanks for the tutorial. When I had the SpatialPerception Capability checked in Unity’s Player Settings, I consistently ran into a build error in Visual Studio “DEP2100: Cannot copy the file “C:\…\bin\x86\Release\resources.pri” to the target machine “”. [0x800704C8] The requested operation cannot be performed on a file with a user-mapped section open…” although I closed Unity before the VS build. I am using Unity 2017.4 and VS Community 2017 v15.6.3 and a HoloLens device. Have you experience the same issues?

    • Posted on April 27, 2018 at 5:01 pm

      I haven’t seen this exact problem, but I would suggest cleaning up all your intermediary files and output files from the unity project by hand. Trying deleting everything that you don’t need to check in. Once you have done that try rebuilding the project which will take a very long time since it will have to regenerate all of those files.


Leave a Reply