# XRShareableAnchorSubsystem

This subsystem provides information regarding 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. Anchors are updated as the device refines its understanding of the environment, allowing you to reliably place virtual content at a real-world pose and sync among all clients.

This base class must be implemented by providers that supply actual shareable anchor capabilities.

## Summary

### Inheritance

Inherits from: `TrackingSubsystem< XRShareableAnchor, XRShareableAnchorSubsystem, XRShareableAnchorSubsystemDescriptor, XRShareableAnchorSubsystem.Provider >`  
Direct Known Subclasses: [`Google.XR.Extensions.SpatialEntities.SpatialShareableAnchorSubsystem`](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/SpatialEntities/SpatialShareableAnchorSubsystem)

| ### Constructors and Destructors ||
|---|---|
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/XRShareableAnchorSubsystem#xrshareableanchorsubsystem()` Reserved for test only. ||

| ### Public functions ||
|---|---|
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/XRShareableAnchorSubsystem#getchanges(Allocator allocator)` | `override TrackableChanges< https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/ARSubsystems/XRShareableAnchor#structGoogle_1_1XR_1_1Extensions_1_1ARSubsystems_1_1XRShareableAnchor >` |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/XRShareableAnchorSubsystem#tryaddanchor(Pose pose, out https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/ARSubsystems/XRShareableAnchor#structGoogle_1_1XR_1_1Extensions_1_1ARSubsystems_1_1XRShareableAnchor anchor)` | `bool` Attempts to create a new anchor at the given *pose* . |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/XRShareableAnchorSubsystem#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/struct/Google/XR/Extensions/ARSubsystems/XRShareableAnchor#structGoogle_1_1XR_1_1Extensions_1_1ARSubsystems_1_1XRShareableAnchor >` Attempts to create a shareable anchor "attached" to the given geospatial pose. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/XRShareableAnchorSubsystem#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)` | `Awaitable< Result< https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/ARSubsystems/XRShareableAnchor#structGoogle_1_1XR_1_1Extensions_1_1ARSubsystems_1_1XRShareableAnchor > >` 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/ARSubsystems/XRShareableAnchorSubsystem#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/ARSubsystems/XRShareableAnchorSubsystem#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/ARSubsystems/XRShareableAnchorSubsystem#tryloadanchorasync(SerializableGuid shareableId, https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrshareableanchorhosts host, CancellationToken cancellationToken)` | `Awaitable< Result< https://developer.android.com/develop/xr/unity/reference/struct/Google/XR/Extensions/ARSubsystems/XRShareableAnchor#structGoogle_1_1XR_1_1Extensions_1_1ARSubsystems_1_1XRShareableAnchor > >` Attempts to load a shareable anchor given its persistent GUID. |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/XRShareableAnchorSubsystem#tryremoveanchor(TrackableId anchorId)` | `bool` Attempts to remove an existing anchor with *anchorId* . |
| `https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/XRShareableAnchorSubsystem#trysaveanchorasync(TrackableId anchorId, 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. |

| ### Classes ||
|---|---|
| [Google.XR.Extensions.ARSubsystems.XRShareableAnchorSubsystem.Provider](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/XRShareableAnchorSubsystem/Provider) | An abstract class to be implemented by providers of this subsystem. |

## Public functions

### GetChanges

```c#
override TrackableChanges< XRShareableAnchor > GetChanges(
  Allocator allocator
)
```

### TryAddAnchor

```c#
bool TryAddAnchor(
  Pose pose,
  out XRShareableAnchor anchor
)
```
Attempts to create a new anchor at the given *pose* .


Details Parameters `pose` The pose, in Unity world space, of the new anchor. `anchor` The output anchor. Valid only if this method returns `true`. The anchor will start with [XRShareableAnchorHosts.None](https://developer.android.com/develop/xr/unity/reference/namespace/Google/XR/Extensions#xrshareableanchorhosts_none). **Returns** `true` if the new anchor was added. Otherwise, `false`.

### TryAttachGeospatialAnchor

```c#
Result< XRShareableAnchor > 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#
Awaitable< Result< XRShareableAnchor > > 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/ARSubsystems/XRShareableAnchorSubsystem#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). **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/ARSubsystems/XRShareableAnchorSubsystem#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). **Returns** The result of the async operation. 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). **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#
Awaitable< Result< XRShareableAnchor > > 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/ARSubsystems/XRShareableAnchorSubsystem#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). **Returns** The result of the async operation, containing the newly added shareable anchor if the operation succeeded. You are responsible to `await` this result.

### TryRemoveAnchor

```c#
bool TryRemoveAnchor(
  TrackableId anchorId
)
```
Attempts to remove an existing anchor with *anchorId* .

If it has been saved by [TrySaveAnchorAsync](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/XRShareableAnchorSubsystem#trysaveanchorasync), the persistent data is not affected.


Details Parameters `anchorId` The TrackableId of an existing anchor to remove. **Returns** `true` if the anchor was removed. Otherwise, `false`.

### TrySaveAnchorAsync

```c#
Awaitable< Result< SerializableGuid > > TrySaveAnchorAsync(
  TrackableId anchorId,
  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/ARSubsystems/XRShareableAnchorSubsystem#tryloadanchorasync) or [TryEraseAnchorAsync](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/XRShareableAnchorSubsystem#tryeraseanchorasync).


**See also:**
[XRShareableAnchorSubsystemDescriptor.supportsSaveAnchor](https://developer.android.com/develop/xr/unity/reference/class/Google/XR/Extensions/ARSubsystems/XRShareableAnchorSubsystemDescriptor#supportssaveanchor)
Details Parameters `anchorId` The TrackableId of the shareable anchor to save. `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). **Returns** The result of the async operation, containing a new persistent GUID if the operation succeeded. You are responsible to `await` this result.

### XRShareableAnchorSubsystem

```c#
 XRShareableAnchorSubsystem()
```
Reserved for test only.