Follow the Basic Passthrough Tutorial. Once you complete that, you will be ready to do the Local Spatial Anchors tutorial.
1. Add Anchor Support
Open the Basic Passthrough Tutorial project
Open Edit > Project Settings > (in Plugins section) > Meta XR.
Enable Anchor Support, Scene Support, and Passthrough Enabled
2. Create two 3D objects to represent Anchors
In the ContentBrowser tab, click + Add > Blueprint Class > Actor to create an actor. Name it BP_NewAnchor
Double click to edit BP_NewAnchor.
Under Components click + Add > Cube
Set Transform > Scale to (0.2,0.2,0.2).
Save and return to the Level Editor.
In the ContentBrowser tab, click + Add > Blueprint Class > Actor to create an actor. Name it BP_OldAnchor
Double click to edit BP_OldAnchor.
In the new opened editor window, under Components click + Add > Sphere
Set Transform > Scale to (0.2,0.2,0.2).
Save and return to the Level Editor.
3. Setup Input Action Mappings for Creating and Loading Anchors
Open Edit > Project Settings... > (in Engine section) > Input.
Add a new Action Mappings for CreateAnchor mapping to Oculus Touch (R) A Press.
Add a new Action Mappings for LoadAnchor mapping to Oculus Touch (R) B Press.
Return to the Level Editor.
Note: This tutorial uses Action Mappings, which are a legacy input system. For UE5 projects, consider using the Enhanced Input system instead.
4. Create “Save Game Class” to Persist Anchor UUIDs
In the ContentBrowser tab, click + Add > Blueprint Class > ALL CLASSES > search > SaveGame. Name it BP_SaveGame.
Double click to edit BP_SaveGame.
Under My Blueprint > VARIABLES > click + to create a new variable. Name it AnchorIds.
On the Details panel:
Set AnchorIds’s Variable Type to String.
Make it an Array.
Tick Instance Editable.
Click Save and Compile.
Return to the Level Editor.
Save Game class will be used as a database to store users created anchor ids.
5. Edit Level Blueprint
Click Blueprint on the toolbar and click Open Level Blueprint.
Under My Blueprint > VARIABLES > click + to create a new variable. Name it tempAnchors.
On the Details panel:
Set AnchorIds’s Variable Type to OculusXRUUID.
Make it an Array.
6. Edit Level Blueprint to Create Anchors
On the Level Blueprint, right-click to create an InputAction CreateAnchor and link it with Spawn Actor from Class to spawn a BP_NewAnchor.
Create a Random Point in Bounding Box with Center = (0, 0, 0) and Half Size = (100, 100, 100) to generate random locations for your new Anchor.
Create a Make Transform and connect Random Point in Bounding Box > Make Transform > SpawnActor BP New Anchor.
Create an OculusXR Async Create Spatial Anchor and connect SpawnActor BP New Anchor, Make Transform for input.
Now users can create anchors by Oculus Touch (R) A Press.
Your Level Blueprint should look like this:
7. Edit Level Blueprint to Save Anchors
With the setup you have in place, the game can generate anchors, but they are only retained within the current game session. To access them in the subsequent game session, you will need to save them. The upcoming steps will provide guidance on how to achieve this.
On the Level Blueprint, create an OculusXR Async Save Anchor and Connect to the previous Blueprint flow.
After saving the Anchor in Oculus, the next step is to store the Anchor UUID within your game so that you can use it to retrieve the anchor from Oculus when needed.
Use Save Game to store the Anchor UUID:
8. Edit Level Blueprint to Load Anchors
With the setup you have in place, the game can generate and save anchors, The upcoming steps will show you how to load saved anchors.
On the Level Blueprint, right-click to create an InputAction LoadAnchor and link it with Load Game from Slot.
Save Game has all persisted Anchor UUIDs, which can be used to load Anchors, detailed Blueprint setup can be found in the below screenshot.
Use OculusXR Async Query Anchors to load anchors by anchor UUIDs.
Use the Query result to Spawn BP_OldAnchor. Your Level Blueprint should look like this:
9. Build and Test
Save project.
Under platforms click Meta Quest device. Unreal will deploy and run APK on the device.
Press your right controller’s A in the game to place anchors into the scene.
Stop the Game and restart the Game.
Press your right controller’s B in the game to load anchors into the scene.
Learn more
For a guide to the Spatial Anchors API with C++ examples, see Use Spatial Anchors.