API reference
API reference
Select your platform
No SDKs available
No versions available

OVRSpatialAnchor Class

Extends MonoBehaviour
Represents a spatial anchor.
A spatial anchor tracks a real-world pose and provides world-locking capability for virtual content. Read more at Spatial Anchor Overview.
This component can be used in two ways: to create a new spatial anchor or to bind to an existing spatial anchor.
To create a new spatial anchor, simply add this component to any GameObject. The transform of the GameObject is used to create a new spatial anchor in the Meta Quest Runtime. Afterwards, the GameObject's transform will be updated automatically. The creation operation is asynchronous, and, if it fails, this component will be destroyed.
Example:
async void CreateSpatialAnchor(GameObject gameObject) {
// Add the component to a GameObject
  var anchor = gameObject.AddComponent\<OVRSpatialAnchor\>();
// Wait for creation+localization
  await anchor.WhenLocalizedAsync();
// Anchor is ready to use
  Debug.Log($"Anchor created at {anchor.transform.position}");
}

Member Enumerations

Enumeration OperationResult

Success
The operation succeeded.
Failure
The operation failed with no additional details.
Failure_DataIsInvalid
The operation failed because the associated data is invalid.
Failure_SpaceCloudStorageDisabled
The operation failed because saving anchors to cloud storage is not permitted by the user.
Failure_SpaceMappingInsufficient
The user was able to download the anchors, but the device was unable to localize itself in the spatial data received from the sharing device.
Failure_SpaceLocalizationFailed
The user was able to download the anchors, but the device was unable to localize them.
Failure_SpaceNetworkTimeout
Network operation timed out.
Failure_SpaceNetworkRequestFailed
Network operation failed.

Events

Action< OperationResult > _onLocalize

Properties

OVRAnchor _anchor[Get]
Event that is dispatched when the anchor is localized.
If the anchor is already localized when a subscriber is added, the subscriber is invoked immediately.Consider WhenLocalizedAsync for a more flexible way to await anchor localization.
The UUID associated with the spatial anchor.
UUIDs persist across sessions. If you load a persisted anchor, you can use the UUID to identify it.
Whether the spatial anchor is created.
Creation is asynchronous and may take several frames. If creation fails, the component is destroyed.
Checks whether the spatial anchor is pending creation.
Whether the spatial anchor is localized.
When you create a new spatial anchor, it may take a few frames before it is localized. Once localized, its transform updates automatically.
(Obsolete) The space associated with the spatial anchor.
The OVRSpace represents the runtime instance of the spatial anchor and will change across different sessions. Deprecated
This property is obsolete. This class provides all spatial anchor functionality and it should not be necessary to use this low-level handle directly. See SaveAsync(), ShareAsync(OVRSpaceUser), and EraseAsync().

Member Functions

Creates an async task that completes when Created becomes true.
Anchor creation is asynchronous, and adding this component to a GameObject will start the creation operation. You can use this async method to await the creation from another async method.This allows you to write code like this:
async Task\<OVRSpatialAnchor\> CreateAnchor(GameObject gameObject) {
  var anchor = gameObject.AddComponent\<OVRSpatialAnchor\>();
  await anchor.WhenCreatedAsync();
return anchor;
}
Returns
Returns a task-like object that can be used to track the completion of the creation. If creation succeeds, the result of the task is true, otherwise false.
Async method that completes when localization completes.
Localization occurs automatically, but the process may take some time. After creating a new OVRSpatialAnchor, you can await this method from within another async method to pause execution until the anchor has been localized.If the localization operation has already completed, this method returns immediately.The bool result of the returned OVRTask<bool> indicates whether localization was successful.To create a new spatial anchor and wait until it is both created and localized, you can use code like this:
async Task\<OVRSpatialAnchor\> CreateAnchor(GameObject gameObject) {
  var anchor = gameObject.AddComponent\<OVRSpatialAnchor\>();
  await anchor.WhenLocalizedAsync();
return anchor; // anchor is localized and ready to use
}
Returns
Returns a task-like object that can be used to track the completion of the asynchronous localization operation.
Shares the anchor to an OVRSpaceUser.
The specified user will be able to download, track, and share specified anchors.This method is asynchronous; use the returned OVRTask to be notified of completion.
Parameters
user
An Oculus user to share the anchor with.
Returns
Returns an OVRTask<OperationResult> indicating the success of the share operation.
Shares the anchor to an OVRSpaceUser.
The specified user will be able to download, track, and share specified anchors.This method is asynchronous; use the returned OVRTask to be notified of completion.
Parameters
user1
An Oculus user to share the anchor with.
user2
An Oculus user to share the anchor with.
Returns
Returns an OVRTask<OperationResult> indicating the success of the share operation.
Shares the anchor to an OVRSpaceUser.
The specified user will be able to download, track, and share specified anchors.This method is asynchronous; use the returned OVRTask to be notified of completion.
Parameters
user1
An Oculus user to share the anchor with.
user2
An Oculus user to share the anchor with.
user3
An Oculus user to share the anchor with.
Returns
Returns an OVRTask<OperationResult> indicating the success of the share operation.
Shares the anchor to an OVRSpaceUser.
The specified user will be able to download, track, and share specified anchors.This method is asynchronous; use the returned OVRTask to be notified of completion.
Parameters
user1
An Oculus user to share the anchor with.
user2
An Oculus user to share the anchor with.
user3
An Oculus user to share the anchor with.
user4
An Oculus user to share the anchor with.
Returns
Returns an OVRTask<OperationResult> indicating the success of the share operation.
Shares the anchor to an OVRSpaceUser.
The specified user will be able to download, track, and share specified anchors.This method is asynchronous; use the returned OVRTask to be notified of completion.
Parameters
users
A collection of Oculus users to share the anchor with.
Returns
Returns an OVRTask<OperationResult> indicating the success of the share operation.
Saves this anchor to persistent storage.
This operation is asynchronous. Use the returned OVRTask to track the result of the asynchronous operation.When saved, an OVRSpatialAnchor can be loaded by a different session. Use the Uuid to identify the same OVRSpatialAnchor at a future time.NOTE: If you have a collection of anchors to save, it is more efficient to use SaveAnchorsAsync.
Returns
Returns an awaitable OVRTask representing the asynchronous save operation.
Erase the anchor from persistent storage.
This operation is asynchronous. Use the returned OVRTask to track the result of the asynchronous operation.NOTE: If you have a collection of anchors to save, it is more efficient to use EraseAnchorsAsync.
Returns
Returns an awaitable OVRTask representing the asynchronous erase operation.
(Obsolete) Initializes this component from an existing space handle and uuid, for example, the result of a call to OVRPlugin.QuerySpaces.
Deprecated
This method is obsolete. To create a new anchor, use
AddComponent\<OVRSpatialAnchor\>()
. To load a previously saved anchor, use LoadUnboundAnchorsAsync.This method associates the component with an existing spatial anchor, for example, the one that was saved in a previous session. Do not call this method to create a new spatial anchor.If you call this method, you must do so prior to the component's Start method. You cannot change the spatial anchor associated with this component after that.
Parameters
space
The existing OVRSpace to associate with this spatial anchor.
uuid
The universally unique identifier to associate with this spatial anchor.
Exceptions
InvalidOperationException
Thrown if Start has already been called on this component.
ArgumentException
Thrown if space is not OVRSpace.Valid.
(Obsolete) Saves the OVRSpatialAnchor to local persistent storage.
This method is asynchronous. Use onComplete to be notified of completion.When saved, an OVRSpatialAnchor can be loaded by a different session. Use the Uuid to identify the same OVRSpatialAnchor at a future time.This operation fully succeeds or fails, which means, either all anchors are successfully saved, or the operation fails. Deprecated
This method is obsolete. Use SaveAsync() instead. To continue using the onComplete callback, use OVRTask<T>.ContinueWith on the returned task.
Parameters
onComplete
Invoked when the save operation completes. May be null. Parameters are
  • OVRSpatialAnchor: The anchor being saved.
  • bool: A value indicating whether the save operation succeeded.
(Obsolete) Saves the OVRSpatialAnchor with specified SaveOptions.
This method is asynchronous. Use onComplete to be notified of completion. When saved, the OVRSpatialAnchor can be loaded by a different session. Use the Uuid to identify the same OVRSpatialAnchor at a future time.This operation fully succeeds or fails; that is, either all anchors are successfully saved, or the operation fails. Deprecated
This method is obsolete. Use SaveAsync() instead. To continue using the onComplete callback, use OVRTask<T>.ContinueWith on the returned task.
Parameters
saveOptions
Save options, e.g., whether local or cloud.
onComplete
Invoked when the save operation completes. May be null. Parameters are
  • OVRSpatialAnchor: The anchor being saved.
  • bool: A value indicating whether the save operation succeeded.
(Obsolete) Shares the anchor to an OVRSpaceUser.
The specified user will be able to download, track, and share specified anchors.This method is asynchronous. Use onComplete to be notified of completion. Deprecated
This method is obsolete. Use ShareAsync(OVRSpaceUser) instead. To continue using the onComplete callback, use OVRTask<T>.ContinueWith on the returned task.
Parameters
user
An Oculus user to share the anchor with.
onComplete
Invoked when the share operation completes. May be null. Delegate parameter is
  • OperationResult: An error code that indicates whether the share operation succeeded or not.
(Obsolete) Shares the anchor with two OVRSpaceUser.
Specified users will be able to download, track, and share specified anchors.This method is asynchronous. Use onComplete to be notified of completion. Deprecated
This method is obsolete. Use ShareAsync(OVRSpaceUser, OVRSpaceUser) instead. To continue using the onComplete callback, use OVRTask<T>.ContinueWith on the returned task.
Parameters
user1
An Oculus user to share the anchor with.
user2
An Oculus user to share the anchor with.
onComplete
Invoked when the share operation completes. May be null. Delegate parameter is
  • OperationResult: An error code that indicates whether the share operation succeeded or not.
(Obsolete) Shares the anchor with three OVRSpaceUser.
Specified users will be able to download, track, and share specified anchors.This method is asynchronous. Use onComplete to be notified of completion. Deprecated
This method is obsolete. Use ShareAsync(OVRSpaceUser, OVRSpaceUser, OVRSpaceUser) instead. To continue using the onComplete callback, use OVRTask<T>.ContinueWith on the returned task.
Parameters
user1
An Oculus user to share the anchor with.
user2
An Oculus user to share the anchor with.
user3
An Oculus user to share the anchor with.
onComplete
Invoked when the share operation completes. May be null. Delegate parameter is
  • OperationResult: An error code that indicates whether the share operation succeeded or not.
(Obsolete) Shares the anchor with four OVRSpaceUser.
Specified users will be able to download, track, and share specified anchors.This method is asynchronous. Use onComplete to be notified of completion. Deprecated
This method is obsolete. Use ShareAsync(OVRSpaceUser, OVRSpaceUser, OVRSpaceUser, OVRSpaceUser) instead. To continue using the onComplete callback, use OVRTask<T>.ContinueWith on the returned task.
Parameters
user1
An Oculus user to share the anchor with.
user2
An Oculus user to share the anchor with.
user3
An Oculus user to share the anchor with.
user4
An Oculus user to share the anchor with.
onComplete
Invoked when the share operation completes. May be null. Delegate parameter is
  • OperationResult: An error code that indicates whether the share operation succeeded or not.
(Obsolete) Shares the anchor to a collection of OVRSpaceUser.
Specified users will be able to download, track, and share specified anchors.This method is asynchronous. Use onComplete to be notified of completion. Deprecated
This method is obsolete. Use ShareAsync(IEnumerable<OVRSpaceUser>). To continue using the onComplete callback, use OVRTask<T>.ContinueWith on the returned task.
Parameters
users
A collection of Oculus users to share the anchor with.
onComplete
Invoked when the share operation completes. May be null. Delegate parameter is
  • OperationResult: An error code that indicates whether the share operation succeeded or not.
(Obsolete) Erases the OVRSpatialAnchor from persistent storage.
This method is asynchronous. Use onComplete to be notified of completion. Erasing an OVRSpatialAnchor does not destroy the anchor. Deprecated
This method is obsolete. Use EraseAsync(). To continue using the onComplete callback, use OVRTask<T>.ContinueWith on the returned task.
Parameters
onComplete
Invoked when the erase operation completes. May be null. Parameters are
  • OVRSpatialAnchor: The anchor being erased.
  • bool: A value indicating whether the erase operation succeeded.
(Obsolete) Erases the OVRSpatialAnchor from specified storage.
This method is asynchronous. Use onComplete to be notified of completion. Erasing an OVRSpatialAnchor does not destroy the anchor. Deprecated
This method is obsolete. Use EraseAsync(EraseOptions). To continue using the onComplete callback, use OVRTask<T>.ContinueWith on the returned task.
Parameters
eraseOptions
Options how the anchor should be erased.
onComplete
Invoked when the erase operation completes. May be null. Parameters are
  • OVRSpatialAnchor: The anchor being erased.
  • bool: A value indicating whether the erase operation succeeded.
(Obsolete) Erases the OVRSpatialAnchor from specified storage.
This method is asynchronous; use the returned OVRTask to be notified of completion. Erasing an OVRSpatialAnchor does not destroy the anchor. Deprecated
This method is obsolete. Use EraseAnchorAsync instead.
Returns
Returns an OVRTask<bool> indicating the success of the erase operation.
(Obsolete) Erases the OVRSpatialAnchor from specified storage.
This method is asynchronous; use the returned OVRTask to be notified of completion. Erasing an OVRSpatialAnchor does not destroy the anchor. Deprecated
This method is obsolete. Use EraseAnchorAsync instead.
Parameters
eraseOptions
Options for how the anchor should be erased.
Returns
Returns an OVRTask<bool> indicating the success of the erase operation.
(Obsolete) Saves the OVRSpatialAnchor with specified SaveOptions.
This method is asynchronous; use the returned OVRTask to be notified of completion. When saved, the OVRSpatialAnchor can be loaded by a different session. Use the Uuid to identify the same OVRSpatialAnchor at a future time.This operation fully succeeds or fails; that is, either all anchors are successfully saved, or the operation fails. Deprecated
This method is obsolete. Use SaveAnchorAsync instead.
Returns
Returns an OVRTask<bool> indicating the success of the save operation.
(Obsolete) Saves the OVRSpatialAnchor with specified SaveOptions.
This method is asynchronous; use the returned OVRTask to be notified of completion. When saved, the OVRSpatialAnchor can be loaded by a different session. Use the Uuid to identify the same OVRSpatialAnchor at a future time.This operation fully succeeds or fails; that is, either all anchors are successfully saved, or the operation fails. Deprecated
This method is obsolete. Use SaveAnchorAsync instead.
Parameters
saveOptions
Options for how the anchor will be saved.
Returns
Returns an OVRTask<bool> indicating the success of the save operation.

Static Member Functions

Shares a collection of anchors with a collection of users.
The users will be able to download, localize, and share the specified anchors.This method is asynchronous. Use the returned OVRTask to monitor completion.This operation fully succeeds or fails, which means, either all anchors are successfully shared or the operation fails.
Parameters
anchors
The collection of anchors to share.
users
An array of Oculus users to share these anchors with.
Returns
Returns a task that can be used to track the completion of the sharing operation.
Exceptions
ArgumentNullException
Thrown if anchors is null.
ArgumentNullException
Thrown if users is null.
Saves a collection of anchors.
This method is asynchronous; use the returned OVRTask to be notified of completion. When saved, the OVRSpatialAnchor can be loaded by a different session. Use LoadUnboundAnchorsAsync(IEnumerable<Guid>,List<UnboundAnchor>,Action<List<UnboundAnchor>,int>) to load some or all OVRSpatialAnchor at a future time.This operation fully succeeds or fails; that is, either all anchors are successfully saved, or the operation fails.
Parameters
anchors
The anchors to save (up to 32).
Returns
Returns an awaitable OVRTask representing the asynchronous save operation.
Exceptions
ArgumentNullException
Thrown if anchors is null.
Exceptions
ArgumentException
Thrown if anchors contains more than 32 anchors.
Erase a collection of anchors from persistent storage.
This operation is asynchronous. Use the returned OVRTask to track the result of the asynchronous operation.The total number of anchors (anchors and uuids ) may not exceed 32.
Parameters
anchors
(Optional) The anchors to erase
uuids
(Optional) The UUIDs to erase
Returns
Returns an awaitable OVRTask representing the asynchronous erase operation.
Exceptions
ArgumentException
Thrown if anchors and uuids are both null.
Exceptions
ArgumentException
Thrown if the combined number of anchors and uuids is greater than 32.
Loads up to 50 unbound anchors with specified UUIDs.
An UnboundAnchor is an anchor that exists, but that isn't managed by an OVRSpatialAnchor. Use this method to load a collection of anchors by UUID that haven't already been bound to an OVRSpatialAnchor.In order to be loaded, the anchor must have previously been persisted, e.g., with SaveAnchorsAsync.NOTE: This method will only process the first 50 UUIDs provided by uuids .This method is asynchronous. The returned OVRTask completes when all results are available. However, anchors may be loaded in batches. To be notified as the results of individual batches are loaded, provide an onIncrementalResultsAvailable callback. The callback accepts two parameters:
(List\<UnboundAnchor\> unboundAnchors, int startingIndex)
  • unboundAnchors is a reference to the unboundAnchors parameter.
  • startingIndex is the index into unboundAnchors which contains the first newly loaded anchor in this batch.
Before the task completes, it is undefined behavior to access unboundAnchors outside of onIncrementalResultsAvailable invocations.Note that if you bind an UnboundAnchor in the onIncrementalResultsAvailable callback, that same anchor will no longer be present in the unboundAnchors provided to future incremental results, or after the task completes. That is, an UnboundAnchor is removed from the list of unboundAnchors once it is bound.unboundAnchors is the buffer used to store the results. This allows you to reuse the same buffer between subsequent calls. The list is cleared before any anchors are added to it.
Parameters
uuids
The UUIDs of the anchors to load.
unboundAnchors
The buffer to store the resulting unbound anchors into.
onIncrementalResultsAvailable
An optional callback that is invoked whenever a new batch of unbound anchors has been loaded.
Returns
A new OVRTask that completes when the loading operation completes.
Exceptions
ArgumentNullException
Thrown if uuids is null.
ArgumentNullException
Thrown if unboundAnchors is null.
Load anchors that have been shared with you.
Use this method to load spatial anchors that have been shared with you by another user.This method requires access to Meta servers to query for shared anchors. This method can fail in a few ways: To load other types of anchors, use LoadUnboundAnchorsAsync(IEnumerable<Guid>,List<UnboundAnchor>,Action<List<UnboundAnchor>,int>).
Parameters
uuids
The set of anchor UUIDs to load
unboundAnchors
A buffer to store the loaded anchors. This container is cleared before being populated.
Returns
Returns an awaitable task-like object that can be used to track completion of the load operation.
Exceptions
ArgumentNullException
Thrown if uuids is null.
ArgumentNullException
Thrown if unboundAnchors is null.
Create an unbound spatial anchor from an OVRAnchor.
Only spatial anchors retrieved as OVRAnchors should use this method. Using this function on system-managed scene anchors will succeed, but certain functions will not work.
Parameters
anchor
The OVRAnchor to create the unbound anchor for.
unboundAnchor
The created unboundAnchor.
Returns
True if anchor is localizable and is not already bound to an OVRSpatialAnchor, otherwise false.
(Obsolete) Performs a query for anchors with the specified options .
Use this method to find anchors that were previously persisted with Save(Action<OVRSpatialAnchor, bool>. The query is asynchronous; when the query completes, onComplete is invoked with an array of UnboundAnchors for which tracking may be requested.
Parameters
options
Options that affect the query.
onComplete
A delegate invoked when the query completes. The delegate accepts one argument:
If the operation fails, onComplete is invoked with null.Deprecated
This method is obsolete. Use LoadUnboundAnchorsAsync. To continue using the onComplete callback, use OVRTask<T>.ContinueWith on the returned task.
Returns
Returns true if the operation could be initiated; otherwise false.
Exceptions
ArgumentNullException
Thrown if onComplete is null.
InvalidOperationException
Thrown if LoadOptions.Uuids of options is null.
(Obsolete) Shares a collection of OVRSpatialAnchor to specified users.
Specified users will be able to download, track, and share specified anchors.This method is asynchronous. Use onComplete to be notified of completion.This operation fully succeeds or fails, which means, either all anchors are successfully shared or the operation fails. Deprecated
This method is obsolete. Use ShareAsync(IEnumerable<OVRSpatialAnchor>,IEnumerable<OVRSpaceUser>) instead. To continue using the onComplete callback, use OVRTask<T>.ContinueWith on the returned task.
Parameters
anchors
The collection of anchors to share.
users
An array of Oculus users to share these anchors with.
onComplete
Invoked when the share operation completes. May be null. Delegate parameter is
  • ICollection<OVRSpatialAnchor>: The collection of anchors being shared.
  • OperationResult: An error code that indicates whether the share operation succeeded or not.
Exceptions
ArgumentNullException
Thrown if anchors is null.
ArgumentNullException
Thrown if users is null.
(Obsolete) Saves a collection of anchors to persistent storage.
This method is asynchronous. Use onComplete to be notified of completion. When saved, an OVRSpatialAnchor can be loaded by a different session. Use the Uuid to identify the same OVRSpatialAnchor at a future time. Deprecated
This method is obsolete. Use SaveAsync(IEnumerable<OVRSpatialAnchor>, SaveOptions) instead. To continue using the onComplete callback, use OVRTask<T>.ContinueWith on the returned task.
Parameters
anchors
Collection of anchors
saveOptions
Save options, e.g., whether local or cloud.
onComplete
Invoked when the save operation completes. May be null. onComplete receives two parameters:
  • ICollection<OVRSpatialAnchor>: The same collection as in anchors parameter
  • OperationResult: An error code indicating whether the save operation succeeded or not.
Exceptions
ArgumentNullException
Thrown if anchors is null.
(Obsolete) Saves a collection of anchors to persistent storage.
This method is asynchronous. Use the returned OVRTask to track the progress of the save operation.When saved, an OVRSpatialAnchor can be loaded in a different session. Use the Uuid to identify the same OVRSpatialAnchor at a future time. Deprecated
This method is obsolete. Use SaveAnchorsAsync instead.
Parameters
anchors
The collection of anchors to save.
saveOptions
Save options, e.g., whether local or cloud.
Returns
Returns a task that represents the asynchronous save operation.
Exceptions
ArgumentNullException
Thrown if anchors is null.
(Obsolete) Performs a query for anchors with the specified options .
Use this method to find anchors that were previously persisted with Save(Action<OVRSpatialAnchor, bool>. The query is asynchronous; when the query completes, the returned OVRTask will contain an array of UnboundAnchors for which tracking may be requested. Deprecated
This method is obsolete. Use LoadUnboundAnchorsAsync(IEnumerable<Guid>,List<UnboundAnchor>,Action<List<UnboundAnchor>, int> instead.
Parameters
options
Options that affect the query.
Returns
Returns an OVRTask with a T:UnboundAnchor[] type parameter containing the loaded unbound anchors.
Exceptions
InvalidOperationException
Thrown if LoadOptions.Uuids of options is null.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon