There are three example projects available on GitHub that showcase anchor functionality.
Spatial anchors sample provides an example for creating, saving, loading, and deleting spatial anchors.
Colocation discovery sample showcases how to create a colocated experience.
Shared spatial anchors sample provides an alternate way to create a colocated experience using an older API.
This page will help you find, download, and use the samples.
After reading this page, you should be able to:
Describe the capabilities of the spatial anchor system as demonstrated in the spatial anchors Sample project.
Explain the use of Unreal’s saving and loading systems to store UUIDs of persisted anchors.
Understand how to share anchors with another user and create a colocated experience.
Spatial anchors sample
How to get the sample
The Spatial Anchors Sample project demonstrates the capabilities of our spatial anchor system. This sample project also provides example code for handling and maintaining spatial anchors, which you can reuse in your project.
Follow the instructions on the github page to install and set up the project.
How to use the sample
Move the thumbstick on the right Touch controller up and down to select menu items.
To create a spatial anchor
Move the thumbstick to hover over “Create Anchor” and then squeeze the trigger.
Save a spatial anchor to storage
Move the thumbstick to hover over “Select Anchor”.
Point to the spatial anchor you want to save and squeeze the trigger.
Move the thumbstick to hover over “Save Anchor” and then press A.
Load a saved spatial anchors back into the app in subsequent sessions
Hover over Load Anchors in the main menu.
Squeeze the trigger and all known anchors should be loaded after a short delay.
Colocation discovery sample
How to get the sample
The Colocation Discovery Sample project demonstrates the capabilities of our spatial anchor system. This sample project also provides example code for creating colocated experiences which you can reuse in your project.
Follow the instructions on the github page to install and set up the project.
How to use the sample
Lobby
When first opening the app you are placed into a waiting room with passthrough enabled. There is a menu attached to your right controller. There are two options.
Create Session: Selecting this option will create a new local network game session that you will automatically be connected to. It will also create a colocation discovery session and advertise it for local players to discover.
Find Session: Selecting “Find Session” will search for nearby colocation discovery sessions that another local player created. If one is found the app will use the metadata in the colocation discovery session to connect to the host automatically, otherwise the text will turn red and you will stay in the lobby.
Shared scene
After creating or joining a session you will be in a passthrough environment. There is a menu attached to your right controller and has the following options:
Create Anchor: Selecting this option will create a new anchor, the position is defined by a preview anchor visible at the top of the controller.
Select Anchor: When hovering over an anchor in the environment, selecting this option will open a new menu specific to anchors.
Load Anchors: This option will load any anchors that were previously saved via the Save Anchors button.
Spawn Cube: Using this option will spawn a networked cube in the environment from the top of your controller.
Explode Cube: Using this menu option while hovering over a cube in the environment will shoot the cube up into the air.
Anchor menu
After spawning and selecting an anchor, an extra menu attached to your right controller appears. This is the anchor menu. Default options are:
Save Anchor(s): Saves the anchor(s) to your local device.
Orient to Anchor: This button makes the origin of the world the specified anchor. If you attempt to use this button with more than one anchor the first selected anchor will be used.
Erase Anchor: Deletes the anchor from the scene, and if saved locally, removes the anchor from local storage.
After saving
After saving the anchor locally, the following options appear:
Unsave Anchor(s): Remove the local anchor from local storage, but do not remove the anchor from the scene.
Hide anchor(s): Hides the visual representation of the anchor from the scene but the anchor is still saved in local storage.
Share Anchors: Share the anchor with any users connected to your session. The other connected users will automatically receive and load the anchors.
Orient to Anchor: Orient the entire scene to the selected anchor.
Erase Anchor: Delete the anchor from the game world and remove it from local storage.
Shared spatial anchors sample
How to get the sample
The Shared Anchors Sample project demonstrates the capabilities of the spatial anchors system. This sample project also provides example code for handling and maintaining spatial anchors, which you may reuse in your own projects. The sample also makes use of Unreal’s saving and loading systems to store the UUIDs of persisted anchors to app storage.
Follow the instructions on the github page to install and set up the project.
How to use the sample
Lobby
When first opening the app you are placed into a waiting room with passthrough enabled. There is a menu attached to your right controller. There are two options.
Create Session: Selecting this option will create a new local network game session that you will automatically be connected to.
Find Session: Selecting “Find Session” will search for an available local internet session that another local player created. If one is found you will connect to it automatically, otherwise the text will turn red and you will stay in the lobby.
Shared scene
After creating or joining a network session you will be in a passthrough environment. There is a menu attached to your right controller and has the following options:
Create Anchor: Selecting this option will create a new anchor, the position is defined by a preview anchor visible at the top of the controller.
Select Anchor: When hovering over an anchor in the environment, selecting this option will open a new menu specific to anchors.
Load Anchors: This option will load any anchors that were previously saved via the Save Anchors button.
Spawn Cube: Using this option will spawn a networked cube in the environment, it will spawn from the top of your controller.
Explode Cube: Using this menu option while hovering over a cube in the environment will shoot the cube up into the air.
Anchor menu
After spawning and selecting an anchor, an extra menu attached to your right controller appears. This is the anchor menu. Default options are:
Save Anchor Locally: Saves the anchor to your local device.
Save Anchor to Cloud: Saves the anchor to cloud storage. After saving to the cloud you can share the anchor with other users of the session.
Orient to Anchor: This button makes the origin of the world the specified anchor. If you attempt to use this button with more than one anchor the first selected anchor will be used.
Erase Anchor: Deletes the anchor from the scene, and if saved locally, removes the anchor from local storage.
Local storage
After saving the anchor locally, the following options appear:
Save Anchor to Cloud: Saves the anchor to cloud storage. After saving to the cloud you can share the anchor with other users of the session.
Unsave Anchor: Remove the local anchor from local storage, but do not remove the anchor from the scene.
Hide anchor: Hides the visual representation of the anchor from the scene but the anchor is still saved in local storage.
Orient to Anchor: Orient the entire scene to the selected anchor.
Erase Anchor: Delete the anchor from the game world and remove it from local storage.
Cloud storage
If you save the anchor to cloud storage, the following options appear:
Save Anchor Locally: Saves the anchor to your local device.
Hide Anchor: Hides the anchor representation, the anchor still exists and you cannot retrieve it when you reboot the app.
Share Anchors: Share the anchor with any users connected to your session. The other connected users will automatically receive and load the anchors.
Orient To Anchor: Orient the entire world to the specified anchor.
Erase Anchor: Erases the anchor representation from the game world but does not remove it from cloud storage.
Learn more
Continue learning about spatial anchors by reading these pages: