More specifically, I’ll add Spectator View to my playground project, which is mainly for placing a hologram in the room (with a few other useful scripts). Currently, this hologram is a nice, life-size skeleton from the Unity asset store.
HoloToolkit-Unity & Holographic Academy
The Holographic Academy course 240 explains how to set up your project to include Shared Holograms. It’s a good idea to work through the tutorial, as it will show you some of the basics of what is needed for Spectator View.
However, as with most of the Academy tutorials, it’s quite old. The HoloToolkit has evolved since then, and the demos often have little resemblance to what your project would look like if you start from scratch.
Therefore, for your own project, first clone the HoloToolkit-Unity GitHub repository to your local PC. Open the project in Unity and export the Assets folder to a new package according to the instructions.
Once this is finished, import your newly made, fresh HoloToolkit-Unity package into your own Unity project. Alternatively, you can of course use one of the pre-packaged HoloToolkit-Unity releases, which is slightly older, but is usually a good compromise.
Building the SpectatorView Unitypackage
After this step is done, the Spectator View instructions state to import also the
SpectatorView_%number%.unitypackage to our project. This is part of the HoloLensCompanionKit repository, not of the HoloToolkit-Unity.
There is a package in the repository that should always be up-to-date against the latest HoloToolkit. However, it wasn’t updated beyond the initial release (at the time of writing) and is therefore 2 months old (based on HoloToolkit 22.214.171.124).
For HoloLens, it’s usually the best to take the latest HoloToolkit code. The HoloToolkit is evolving rapidly, and the previous 2 months have seen a lot of bug fixes.
So, how to build the SpectatorView Unity package using the latest HoloToolkit sources? Let’s see what is inside the
SpectatorView_1_5_5_0.unitypackage file. If you rename it to
.zip , you can open it with your favorite archive manager. By looking at the included pathname files, you can get the original filename that is included. For example, the following folder would be in the unitypackage
It turns out that the Unity package contains the HolographicCameraRig, which is only part of the SharedHolograms sample in the SpectatorView GitHub repository. For us this means that we need to take a part of the sample and put this into our custom project.
Therefore, let’s export the latest version from that part of the SharedHolograms sample into another Unity package. Open that in Unity, right-click on HolographicCameraRig and choose Export package…
Make sure you only export that single asset folder, not all the assets from the sample:
In the folder of that package, you will see several TODO.txt files from Microsoft. These remind us that we will need to copy the compiled DLL files of the Compositor to our project as well.
Compositor DLL files
We have already compiled the Compositor in the previous step. Now, we just need to copy the DLL files to our own project. As my custom project of course isn’t inside the folder structure of the SpectatorView GitHub repository, we need to be careful as for the parameters to provide for the CopyDLL.cmd batch file in the main folder of the repo.
Looking at the source of the batch file, we see that the copy commands expect the path of the assets folder of our own project as parameter:
copy "%~dp0\Compositor\Release\UnityCompositorInterface.pdb" "%~1\Addons\HolographicCameraRig\Plugins\x86\"
Simply specifying the absolute path worked fine for me:
Next, restart Unity and open our project once again.
The TODO.txt file from the HolographicCameraRig specifies as the next step to replace CalibrationData.txt with our own file. So, we’ll copy our calibration data file that we created in Step 3 directly into the Assets folder of our own project.
Adding the Spectator View
Now, let’s slowly get to the exciting part: actually adding the spectator view to our project. Drag the Assets > Addons > HolographicCameraRig > Prefabs > SpectatorViewManager prefab to our Hierarchy panel.
Unfortunately, this results in a compile error. The spatial mapping code in the HoloToolkit apparently had a breaking change during the last two months that wasn’t updated in the Spectator View so far.
So we have two options:
- Use a really old HoloToolkit (with all the negative implications that come with that).
- Fixing the Spectator View to work with the latest HoloToolkit.
We’ll continue our journey to Spectator View in an our own project in the next part of the blog series!
HoloLens Spectator View blog post series
This post is part of a short series that guides you through integrating HoloLens Spectator View into your own Mixed Reality app: