ARShareableAnchorManager

A trackable manager that enables placing, tracking, saving and loading shareable anchors.

A shareable anchor is a pose (position and rotation) in the physical environment that is tracked by an XR device. It can then be saved on a host for sharing among different clients, so that each client can retrieve the same anchor from the physical environment.

Summary

Inheritance

Inherits from: ARTrackableManager< XRShareableAnchorSubsystem, XRShareableAnchorSubsystemDescriptor, XRShareableAnchorSubsystem.Provider, XRShareableAnchor, ARShareableAnchor >

Properties

shareableAnchorPrefab
GameObject
Gets or sets the prefab which is used to instantiate each ARShareableAnchor.

Public functions

GetShareableAnchor(TrackableId trackableId)
Gets the ARShareableAnchor with given trackableId , or null if no such anchor exists.
TryAddAnchor(Pose pose)
Attempts to create a new anchor at the given pose .
TryAttachGeospatialAnchor(XRGeospatialPose geospatialPose)
Result< ARShareableAnchor >
Attempts to create a shareable anchor "attached" to the given geospatial pose.
TryAttachSurfaceAnchorAsync(XRGeospatialSurfaceType type, XRGeospatialPose geospatialPose, CancellationToken cancellationToken)
async Awaitable< Result< ARShareableAnchor > >
Attempts to create a shareable anchor "attached" to the given geospatial pose relative to the location's surface.
TryEraseAnchorAsync(SerializableGuid shareableId, XRShareableAnchorHosts host, CancellationToken cancellationToken)
Awaitable< XRResultStatus >
Attempts to erase the persistent saved data associated with an anchor given its persistent GUID.
TryGetSavedAnchorIdsAsync(XRShareableAnchorHosts host, Allocator allocator, CancellationToken cancellationToken)
Awaitable< Result< NativeArray< SerializableGuid > > >
Attempts to get a NativeArray containing all saved persistent GUIDs from the given host.
TryLoadAnchorAsync(SerializableGuid shareableId, XRShareableAnchorHosts host, CancellationToken cancellationToken)
async Awaitable< Result< ARShareableAnchor > >
Attempts to load a shareable anchor given its persistent GUID.
TryRemoveAnchor(ARShareableAnchor anchor)
bool
Attempts to remove a shareable anchor.
TrySaveAnchorAsync(ARShareableAnchor anchor, XRShareableAnchorHosts host, CancellationToken cancellationToken)
Awaitable< Result< SerializableGuid > >
Attempts to persistently save the given anchor so that it can be loaded in a future session.

Properties

shareableAnchorPrefab

GameObject shareableAnchorPrefab

Gets or sets the prefab which is used to instantiate each ARShareableAnchor.

May be null.

The purpose of this property is to extend the functionality of ARShareableAnchors. It is not the recommended way to instantiate content associated with an ARShareableAnchor.

Public functions

GetShareableAnchor

ARShareableAnchor GetShareableAnchor(
  TrackableId trackableId
)

Gets the ARShareableAnchor with given trackableId , or null if no such anchor exists.

Details
Parameters
trackableId
The TrackableId of the ARShareableAnchor to retrieve.
Returns
The ARShareableAnchor or null.

TryAddAnchor

ARShareableAnchor TryAddAnchor(
  Pose pose
)

Attempts to create a new anchor at the given pose .

Details
Parameters
pose
The pose, in Unity world space, of the anchor.
Returns
A new ARShareableAnchor if successful, otherwise null.

TryAttachGeospatialAnchor

Result< ARShareableAnchor > TryAttachGeospatialAnchor(
  XRGeospatialPose geospatialPose
)

Attempts to create a shareable anchor "attached" to the given geospatial pose.

See also: XRShareableAnchorSubsystemDescriptor.supportsAttachGeospatialAnchor

Details
Parameters
geospatialPose
The geospatial pose of the target location.
Returns
The result of the operation, containing the newly added shareable anchor if the operation succeeded. The anchor will start with XRShareableAnchorHosts.Geospatial and XRGeospatialSurfaceType.Default.

TryAttachSurfaceAnchorAsync

async Awaitable< Result< ARShareableAnchor > > TryAttachSurfaceAnchorAsync(
  XRGeospatialSurfaceType type,
  XRGeospatialPose geospatialPose,
  CancellationToken cancellationToken
)

Attempts to create a shareable anchor "attached" to the given geospatial pose relative to the location's surface.

See also: XRShareableAnchorSubsystemDescriptor.supportsAttachSurfaceAnchor

Details
Parameters
type
The surface type of the geospatial anchor, determining how to apply the relative altitude from geospatialPose . When passing XRGeospatialSurfaceType.Default, it works the same as TryAttachGeospatialAnchor.
geospatialPose
The geospatial pose of the target location where XRGeospatialPose.Altitude represents the altitude in meters relative to the surface.
cancellationToken
An optional CancellationToken that you can use to cancel the operation in progress if the loaded provider XRShareableAnchorSubsystemDescriptor.supportsAsyncCancellation.
Exceptions
OperationCanceledException
Thrown if the operation has been canceled either by the caller or the Unity main thread.
Returns
The result of the async operation, containing the newly added shareable anchor if the operation succeeded. The anchor will start with XRShareableAnchorHosts.Geospatial and type . You are responsible to await this result.

TryEraseAnchorAsync

Awaitable< XRResultStatus > TryEraseAnchorAsync(
  SerializableGuid shareableId,
  XRShareableAnchorHosts host,
  CancellationToken cancellationToken
)

Attempts to erase the persistent saved data associated with an anchor given its persistent GUID.

See also: XRShareableAnchorSubsystemDescriptor.supportsEraseAnchor

Details
Parameters
shareableId
A persistent GUID created by TrySaveAnchorAsync.
host
The target host to erase this persistent id.
cancellationToken
An optional CancellationToken that you can use to cancel the operation in progress if the loaded provider XRShareableAnchorSubsystemDescriptor.supportsAsyncCancellation.
Exceptions
OperationCanceledException
Thrown if the operation has been canceled either by the caller or the Unity main thread.
Returns
The result of the async operation. If the operation failed, you may also check with XrResultExtensions.IsPersistenceResult to determine whether it failed with PersistenceStatusCode.PersistUuidNotFound. You are responsible to await this result.

TryGetSavedAnchorIdsAsync

Awaitable< Result< NativeArray< SerializableGuid > > > TryGetSavedAnchorIdsAsync(
  XRShareableAnchorHosts host,
  Allocator allocator,
  CancellationToken cancellationToken
)

Attempts to get a NativeArray containing all saved persistent GUIDs from the given host.

See also: XRShareableAnchorSubsystemDescriptor.supportsGetSavedAnchorIds

Details
Parameters
host
The host to retrieve all saved anchors.
allocator
The allocation strategy to use for the resulting NativeArray.
cancellationToken
An optional CancellationToken that you can use to cancel the operation in progress if the loaded provider XRShareableAnchorSubsystemDescriptor.supportsAsyncCancellation.
Exceptions
OperationCanceledException
Thrown if the operation has been canceled either by the caller or the Unity main thread.
Returns
The result of the async operation, containing a NativeArray of persistent GUIDs allocated with the given allocator if the operation succeeded. You are responsible to await this result.

TryLoadAnchorAsync

async Awaitable< Result< ARShareableAnchor > > TryLoadAnchorAsync(
  SerializableGuid shareableId,
  XRShareableAnchorHosts host,
  CancellationToken cancellationToken
)

Attempts to load a shareable anchor given its persistent GUID.

See also: XRShareableAnchorSubsystemDescriptor.supportsLoadAnchor

Details
Parameters
shareableId
A persistent GUID created by TrySaveAnchorAsync.
host
The target host to load this persistent id.
cancellationToken
An optional CancellationToken that you can use to cancel the operation in progress if the loaded provider XRShareableAnchorSubsystemDescriptor.supportsAsyncCancellation.
Exceptions
OperationCanceledException
Thrown if the operation has been canceled either by the caller or the Unity main thread.
Returns
The result of the async operation, containing the newly added shareable anchor if the operation succeeded. If the operation failed, you may also check with XrResultExtensions.IsPersistenceResult to determine whether it failed with PersistenceStatusCode.PersistUuidNotFound. You are responsible to await this result.

TryRemoveAnchor

bool TryRemoveAnchor(
  ARShareableAnchor anchor
)

Attempts to remove a shareable anchor.

Details
Parameters
anchor
The ARShareableAnchor to remove.
Returns
Returns true if successful, otherwise false.

TrySaveAnchorAsync

Awaitable< Result< SerializableGuid > > TrySaveAnchorAsync(
  ARShareableAnchor anchor,
  XRShareableAnchorHosts host,
  CancellationToken cancellationToken
)

Attempts to persistently save the given anchor so that it can be loaded in a future session.

Use the SerializableGuid returned by this method as an input parameter to TryLoadAnchorAsync or TryEraseAnchorAsync.

See also: XRShareableAnchorSubsystemDescriptor.supportsSaveAnchor

Details
Parameters
anchor
The ARShareableAnchor to save. You can create a shareable anchor using TryAddAnchor.
host
The target host to save this anchor.
cancellationToken
An optional CancellationToken that you can use to cancel the operation in progress if the loaded provider XRShareableAnchorSubsystemDescriptor.supportsAsyncCancellation.
Exceptions
OperationCanceledException
Thrown if the operation has been canceled either by the caller or the Unity main thread.
Returns
The result of the async operation, containing a new persistent GUID if the operation succeeded. If the operation failed, you may also check with XrResultExtensions.IsPersistenceResult for any persistence reasons. You are responsible to await this result.