Azure Spatial Anchors is a Microsoft Mixed Reality service, allowing augmented reality devices to discover, share, and persist anchor points in the physical world. Documentation below provides instructions for integrating the Azure Spatial Anchors service into an Unreal project. If you’re looking for more information, check out the Azure Spatial Anchors service.
[!NOTE] Unreal Engine 4.26 now has plugins for ARKit and ARCore support if you’re targeting iOS or Android.
[!IMPORTANT] Local anchors are stored on device, while Azure Spatial Anchors are stored in the cloud. If you’re looking to store your anchors locally on a device, we have a Local Spatial Anchors document that can walk you through the process. Note that you can have local and Azure anchors in the same project without conflict.
To complete this guide, make sure you have:
Before using Azure Spatial Anchors in your project, you need to:
Check out the Azure Spatial Anchors authentication docs for more information.
[!NOTE] Azure Spatial Anchors in Unreal 4.25 does not support Azure AD authentication tokens, but support for this functionality will be coming in a later release.
Open Project Settings > HoloLens and enable the Internet Client capability:
For an Android app to display a permission dialogue and allow location capabilities, the Request Android Permissions function must be called before attempting to start the Azure Spatial Anchor session:
Create a local variable for the input permissions, and populate with:
Finally, open Project Settings > Android and set the same permissions in the Extra Permissions field under Advanced APK Packaging:
To build an application for iOS, you will need to use Unreal on a Mac. To package with an Apple developer account, open Project Settings > iOS and scroll down to the Build section. Enable the Automatic Signing checkbox and populate the IOS Team ID with your Team ID.
You can find your Team ID by logging into developer.apple.com, navigating to the Membership tab and searching for Team ID.
To display a permission dialogue and allow the iOS device to access location information, the Init Location Services and Start Location Services functions must be called before attempting to start the Azure Spatial Anchor session:
Enable the Azure Spatial Anchors plugins in the Unreal editor by:
Once that’s done, restart the Unreal Editor for the plugin changes to take effect. The project is now ready to use Azure Spatial Anchors.
Enable the Azure Spatial Anchors plugins in the Unreal editor by:
Once that’s done, restart the Unreal Editor for the plugin changes to take effect. The project is now ready to use Azure Spatial Anchors.
Enable the Azure Spatial Anchors plugins in the Unreal editor by:
Once that’s done, restart the Unreal Editor for the plugin changes to take effect. The project is now ready to use Azure Spatial Anchors.
An Azure Spatial Anchors session allows client applications to communicate with the Azure Spatial Anchors service. You’ll need to create and start an Azure Spatial Anchors session to create, persist, and share Azure Spatial Anchors:
Start an Azure Spatial Anchors session by:
It’s good practice to clean up Azure Spatial Anchors resources in your Event Graph blueprint when you’re no longer using the service:
Your Event Graph blueprint should look like the screenshot below:
An Azure Spatial Anchor represents a physical world pose in the augmented reality application space, which locks augmented reality content to physical locations. Azure Spatial Anchors can also be shared among different users. This sharing allows augmented reality content drawn on different devices to be positioned in the same location in the physical world.
To create a new Azure Spatial Anchor:
To construct and save an Azure Spatial Anchor for an Unreal Scene Component:
After setting anchor parameters, declare the anchor as ready to save. In the example below, the newly created Azure Spatial Anchor is added to a set of Azure Spatial Anchors needing saving. This set is declared as a variable for the Pawn blueprint.
After configuring the Azure Spatial Anchor with your parameters, call Save Cloud Anchor. Save Cloud Anchor declares the anchor to the Azure Spatial Anchors service. When the call to Save Cloud Anchor succeeds, the Azure Spatial Anchor is available to other users of the Azure Spatial Anchor service.
[!NOTE] Save Cloud Anchor is an asynchronous function and can only be called on a game thread event such as EventTick. Save Cloud Anchor may not appear as an available blueprint function in custom blueprint Functions. However, it should be available in the Pawn Event Graph blueprint editor.
In the example below, the Azure Spatial Anchor is stored in a set during an input event callback. The anchor is then saved on the EventTick. Saving an Azure Spatial Anchor may take multiple attempts depending on the amount of spatial data that your Azure Spatial Anchors session has created. That’s why it’s a good idea to check whether the save call succeeded.
If the anchor doesn’t save, readd it to the set of anchors still needing to be saved. Future EventTicks will keep trying to save the anchor until it’s successfully stored.
Once the anchor saves, the AR Pins’ transform acts as a reference transform for placing content in your app. Other users can detect this anchor and align AR content for different devices in the physical world.
You can delete anchors from the Azure Spatial Anchor service by calling Delete Cloud Anchor.
[!NOTE] Delete Cloud Anchor is a latent function and can only be called on a game thread event, such as EventTick. Delete Cloud Anchor may not appear as an available blueprint function in custom blueprint Functions. It should however be available in the Pawn Event Graph blueprint editor.
In the example below, the anchor is flagged for deletion on a custom input event. The deletion is then attempted on the EventTick. If the anchor deletion fails, add the Azure Spatial Anchor to the set of anchors flagged for deletion and tries again on later EventTicks.
Your Event Graph blueprint should now look like the screenshot below:
Existing anchors can be created by peers with the Azure Spatial Anchors service:
To locate Azure Spatial Anchors created by peers using the Azure Spatial Anchor service, the application will have to create an Azure Spatial Anchors Watcher:
The application now begins looking for Azure Spatial Anchors known to the Azure Spatial Anchors service, meaning that users can locate Azure Spatial Anchors created by their peers.
After locating the Azure Spatial Anchor, call Stop Watcher to stop the Azure Spatial Anchors Watcher and clean up watcher resources.
Your final Event Graph blueprint should now look like the screenshot below:
If you’re following the Unreal development journey we’ve laid out, you’re in the midst of exploring the MRTK core building blocks. From here, you can continue to the next building block:
[!div class=”nextstepaction”] Spatial mapping
Or jump to Mixed Reality platform capabilities and APIs:
[!div class=”nextstepaction”] HoloLens camera
You can always go back to the Unreal development checkpoints at any time.