# 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 ||
|---|---|
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#shareableanchorprefab` | `GameObject` Gets or sets the prefab which is used to instantiate each [ARShareableAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor). |

| ### Public functions ||
|---|---|
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#getshareableanchor(TrackableId trackableId)` | `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor` Gets the [ARShareableAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor) with given *trackableId* , or `null` if no such anchor exists. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#tryaddanchor(Pose pose)` | `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor` Attempts to create a new anchor at the given *pose* . |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#tryattachgeospatialanchor(https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/XRGeospatialPose#structGoogle_1_1XR_1_1Extensions_1_1XRGeospatialPose geospatialPose)` | `Result< https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor >` Attempts to create a shareable anchor "attached" to the given geospatial pose. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#tryattachsurfaceanchorasync(https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrgeospatialsurfacetype type, https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/XRGeospatialPose#structGoogle_1_1XR_1_1Extensions_1_1XRGeospatialPose geospatialPose, CancellationToken cancellationToken)` | `async Awaitable< Result< https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor > >` Attempts to create a shareable anchor "attached" to the given geospatial pose relative to the location's surface. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#tryeraseanchorasync(SerializableGuid shareableId, https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrshareableanchorhosts host, CancellationToken cancellationToken)` | `Awaitable< XRResultStatus >` Attempts to erase the persistent saved data associated with an anchor given its persistent GUID. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#trygetsavedanchoridsasync(https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrshareableanchorhosts host, Allocator allocator, CancellationToken cancellationToken)` | `Awaitable< Result< NativeArray< SerializableGuid > > >` Attempts to get a NativeArray containing all saved persistent GUIDs from the given host. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#tryloadanchorasync(SerializableGuid shareableId, https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrshareableanchorhosts host, CancellationToken cancellationToken)` | `async Awaitable< Result< https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor > >` Attempts to load a shareable anchor given its persistent GUID. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#tryremoveanchor(https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor anchor)` | `bool` Attempts to remove a shareable anchor. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#trysaveanchorasync(https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor anchor, https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#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

```c#
GameObject shareableAnchorPrefab
```
Gets or sets the prefab which is used to instantiate each [ARShareableAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor).

May be `null`.

The purpose of this property is to extend the functionality of [ARShareableAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor)s. It is not the recommended way to instantiate content associated with an [ARShareableAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor).

## Public functions

### GetShareableAnchor

```c#
ARShareableAnchor GetShareableAnchor(
  TrackableId trackableId
)
```
Gets the [ARShareableAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor) with given *trackableId* , or `null` if no such anchor exists.


Details Parameters `trackableId` The TrackableId of the [ARShareableAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor) to retrieve. **Returns** The [ARShareableAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor) or `null`.

### TryAddAnchor

```c#
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](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor) if successful, otherwise `null`.

### TryAttachGeospatialAnchor

```c#
Result< ARShareableAnchor > TryAttachGeospatialAnchor(
  XRGeospatialPose geospatialPose
)
```
Attempts to create a shareable anchor "attached" to the given geospatial pose.


**See also:**
[XRShareableAnchorSubsystemDescriptor.supportsAttachGeospatialAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/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](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrshareableanchorhosts_geospatial) and [XRGeospatialSurfaceType.Default](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrgeospatialsurfacetype_default).

### TryAttachSurfaceAnchorAsync

```c#
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](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/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](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrgeospatialsurfacetype_default), it works the same as [TryAttachGeospatialAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#tryattachgeospatialanchor). `geospatialPose` The geospatial pose of the target location where [XRGeospatialPose.Altitude](https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/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](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/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](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrshareableanchorhosts_geospatial) and *type* . You are responsible to `await` this result.

### TryEraseAnchorAsync

```c#
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](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/XRShareableAnchorSubsystemDescriptor#supportseraseanchor)
Details Parameters `shareableId` A persistent GUID created by [TrySaveAnchorAsync](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#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](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/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](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XrResultExtensions#ispersistenceresult) to determine whether it failed with [PersistenceStatusCode.PersistUuidNotFound](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#persistencestatuscode_persistuuidnotfound). You are responsible to `await` this result.

### TryGetSavedAnchorIdsAsync

```c#
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](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/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](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/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

```c#
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](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/XRShareableAnchorSubsystemDescriptor#supportsloadanchor)
Details Parameters `shareableId` A persistent GUID created by [TrySaveAnchorAsync](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#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](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/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](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XrResultExtensions#ispersistenceresult) to determine whether it failed with [PersistenceStatusCode.PersistUuidNotFound](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#persistencestatuscode_persistuuidnotfound). You are responsible to `await` this result.

### TryRemoveAnchor

```c#
bool TryRemoveAnchor(
  ARShareableAnchor anchor
)
```
Attempts to remove a shareable anchor.


Details Parameters `anchor` The [ARShareableAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor) to remove. **Returns** Returns `true` if successful, otherwise `false`.

### TrySaveAnchorAsync

```c#
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](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#tryloadanchorasync) or [TryEraseAnchorAsync](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#tryeraseanchorasync).


**See also:**
[XRShareableAnchorSubsystemDescriptor.supportsSaveAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/XRShareableAnchorSubsystemDescriptor#supportssaveanchor)
Details Parameters `anchor` The [ARShareableAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchor#classGoogle_1_1XR_1_1Extensions_1_1ARShareableAnchor) to save. You can create a shareable anchor using [TryAddAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARShareableAnchorManager#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](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/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](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/XrResultExtensions#ispersistenceresult) for any persistence reasons. You are responsible to `await` this result.