Spatial anchors are world-locked frames of reference you can use to position
content. They are rigid transforms that represent fixed physical locations in
the real
You can use spatial anchors to enrich the user experience in many ways, such as
placing virtual signs on real furniture, or creating spawn points on real
windows for virtual characters to fly through.
Anchor Lifecycle
You can create, save, share, discover, erase, and destroy spatial
anchors. We will examine each of these in the following sections.
Anchor identifiers
Each anchor has a universally unique identifier (UUID) associated with it. If
you want to manage content rendered against an anchor across sessions or shared
with others, you’ll need to keep track of a mapping of the anchor’s UUID to the
content it’s associated with.
Create a Spatial Anchor
Spatial Anchors are Most Effective within 3 Meters
Create a spatial anchor within 3m of the object you want to anchor. Otherwise, your pose will be incorrect due to drift (that is, even though the location of the spatial anchor remains the same, the farther the user moves away from the spatial anchor, the greater the drift of the objects attached to the spatial anchor will seem to that user). If you attach content to a nearby anchor (within 3m), it will remain in place relative to the anchor, even if the user goes farther away than 3m.
You can create a spatial anchor by using the xrCreateSpatialAnchorFB API. See
the
API Reference page
for more.
Localize and Track a Spatial Anchor
A spatial anchor will be locatable at the time of creation, you can call
xrLocateSpace every frame with the reference space used to create the anchor.
Read more about the
xrLocateSpace
API in the OpenXR specification.
In order to track an anchor from different sources (e.g., discovery, query),
you must first localize it by successfully calling xrSetSpaceComponentStatusFB
with the XR_SPACE_COMPONENT_TYPE_LOCATABLE_FB component on the anchor. You can
then call xrLocateSpace on it.
Save a Spatial Anchor
Spatial anchors can be persisted beyond the lifetime of an app’s session. This
allows you to recover a previously created spatial anchor the next time the user
runs your app, providing a greater sense of connection with the real world.
In order to persist a spatial anchor, you must first enable the
XR_SPACE_COMPONENT_TYPE_STORABLE_FB component on the anchor. You can do this
by calling xrSetSpaceComponentStatusFB with the
XR_SPACE_COMPONENT_TYPE_STORABLE_FB component. You can then save a Spatial
Anchor by calling the xrSaveSpacesMETA API. See the
API Reference page
for more.
Discover an Anchor
You can discover a collection of anchors from various sources. It will return
previously app-persisted anchors and system-persisted anchors (i.e. the Scene
Model).
You can Discover anchors by using the xrDiscoverSpacesMETA API. See the
API Reference page
for more.
Share a Spatial Anchor
You can share anchors with other users to enable local colocation experiences.
Before sharing an anchor, you must first enable the
XR_SPACE_COMPONENT_TYPE_SHARABLE_FB component on the anchor. You can do this
by calling xrSetSpaceComponentStatusFB with the
XR_SPACE_COMPONENT_TYPE_SHARABLE_FB component on the anchor. You can then
share a spatial anchor by using the xrShareSpacesMETA API. See the
API Reference page
for more.
Query for a Shared Anchor
You can query for anchors which were shared with you.
You can Query for shared anchors by using the xrQuerySpacesFB API by
specifying Cloud as the Storage Location and specifying either the UUIDs for the
anchors shared to you, or the Group UUID the anchors were shared with. See the
API Reference page
for more.
Erase a Spatial Anchor
A spatial anchor can be erased from persist storage. Note that erasing an
anchor is different from destroying an anchor. Erase removes it from
persistent storage, but does not affect existing runtime instances already
loaded into memory. Once erased, a spatial anchor will not be available in
future sessions.
You can erase an anchor, either by its XrSpace handle or by its UUID, via the
xrEraseSpacesMETA API, if the anchor’s XR_SPACE_COMPONENT_TYPE_STORABLE_FB
component is enabled. See the
API Reference page
for more.
Destroy an Anchor
When you destroy a spatial anchor, you destroy the runtime instance. Note this
does not affect the state of the anchor in persist storage. Although a virtual
object that was using the spatial anchor remains, its transforms will no longer
be driven by the spatial anchor, so it is no longer locked to its previous
real-world location.
You can destroy an anchor by using the xrDestroySpace API. Read more about
xrDestroySpace
in the OpenXR specification.