How to serialize Hololens 2 Anchors

Work in progress

Summary

I will describe how you can serialize HoloLens 2 anchors. This data can then be used to import and export the data. This allows you to persist the data either locally on a single HoloLens or to share the anchors between multiple devices.

Requirements

  • Unity 2020+
  • OpenXR plugin
  • ARFoundation
  • HoloLens 2
    • HoloLens 1 does not support OpenXR, but the old method should still work with unity 2019.
  • MRTK v2 (v3 probably also works, but haven’t tested it) Not necessary for serializing of anchors

Setup

The OpenXR plugin and ARFoundation can be installed via the Mixed Reality Feature Tool.

Make sure you have the AR Anchor Manager component in the scene. I’ve got my scene setup as follows:

Then you need an ARFoundation ARAnchor attached on the object on the location that you want to save.

The following script allows you to import/export a Microsoft MixedReality (HoloLens) anchor.

To read all the LansAnchor content you need to unlock the license.

You must be logged in to view this content.

You will also need the following three files.

You must be logged in to view this content.

Using these files you can now Import/Export an Anchor! This data can be used to anchor HoloLenses around a single point in a room, to create a multiplayer experience!

Multiplayer

If you want players to see the information based around the Persistent Spatial Anchor you will need to make sure that the shared content in the scene is all placed relative to the anchor.
For example:
– LansAnchor
– Cube with a localPosition of (0,0,0)
This will show all the Cube to all users at the location of the Anchor.

Usage of asset

LansAnchor.Export

If you want to use the script directly to serialize HoloLens anchors you can utilize the two functions. The first function, byte[] Export(ARAnchor[] anchors), converts an array of anchors into a byte array, enabling you to save or share this data for future use.

LansAnchor.Import

The second, void Import(byte[] data, Action<AnchorLocated> onAnchorLocated), imports previously exported data back into the system, allowing you to load HoloLens anchors and trigger an action when each anchor is successfully located.

This data can be saved locally, offline or shared with your networking solution of choice. Using this way of sharing anchors allows you to share the anchors without needing a live connection like the (retired) Azure Spatial Anchors.

LansAnchors can be used as an alternative to Azure Spatial Anchors.

Projects that use local sharing of anchors

Troubleshooting

Please let me know if this information helped you! If you couldn’t make it work. Please contact me!

Unity Package

I’m working on releasing this code to the Unity Asset store. ETA Q3 2025.

Pricing

View the LansAnchor page to learn about the pricing. Note that the current prices are placeholders and I’m willing to negotiate on the prices.

Other Projects