Local Spatial Anchors Tutorial
- Open the Basic Passthrough Tutorial project
- Open Edit > Project Settings > (in Plugins section) > Meta XR.
- Enable Anchor Support, Scene Support and Passthrough Support
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 back to the main scene window.
- 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 back to the main scene window.
- 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.
- Back to the main scene window.
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.
- Back to the main scene window.
Save Game class will be used as a database to store users created anchor ids.
- 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 Oculus XRUUIDD.
- 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 a Oculus XRAsync 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 set 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 a Oculus XRAsync 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 Oculus XRAsync Query Anchors to load anchors by Anchor UUIDs.
- Use the Query result to Spawn BP_OldAnchor. Your Level Blueprint should set like this:
- 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.