Class ARAnchorManager
A trackable manager that enables you to add and track anchors. Add this component to your XR Origin GameObject to enable anchor tracking in your app.
Inheritance
Implements
Inherited Members
Namespace: UnityEngine.XR.ARFoundation
Assembly: Unity.XR.ARFoundation.dll
Syntax
[DefaultExecutionOrder(-2147483647)]
[DisallowMultipleComponent]
[RequireComponent(typeof(XROrigin))]
[AddComponentMenu("XR/AR Foundation/AR Anchor Manager")]
public sealed class ARAnchorManager : ARTrackableManager<XRAnchorSubsystem, XRAnchorSubsystemDescriptor, XRAnchorSubsystem.Provider, XRAnchor, ARAnchor>, ITrackablesChanged<ARAnchor>
Remarks
An anchor is a pose (position and rotation) in the physical environment that is tracked by an XR device. Anchors are updated as the device refines its understanding of the environment, allowing you to reliably place mixed reality content at a physical pose.
Related information: Anchors
Properties
anchorPrefab
Declaration
public GameObject anchorPrefab { get; set; }
Property Value
Type | Description |
---|---|
GameObject |
Remarks
The purpose of this property is to extend the functionality of ARAnchors. It is not the recommended way to instantiate content associated with an ARAnchor.
gameObjectName
The name to assign to the GameObject instantiated for each ARAnchor.
Declaration
protected override string gameObjectName { get; }
Property Value
Type | Description |
---|---|
string |
Overrides
Methods
AttachAnchor(ARPlane, Pose)
Attempts to create a new anchor that is attached to an existing ARPlane.
Declaration
public ARAnchor AttachAnchor(ARPlane plane, Pose pose)
Parameters
Type | Name | Description |
---|---|---|
ARPlane | plane | The ARPlane to which to attach. |
Pose | pose | The initial pose, in Unity world space, of the anchor. |
Returns
Type | Description |
---|---|
ARAnchor |
GetAnchor(TrackableId)
Declaration
public ARAnchor GetAnchor(TrackableId trackableId)
Parameters
Type | Name | Description |
---|---|---|
TrackableId | trackableId | The TrackableId of the ARAnchor to retrieve. |
Returns
Type | Description |
---|---|
ARAnchor |
GetPrefab()
Get the prefab to instantiate for each ARAnchor.
Declaration
protected override GameObject GetPrefab()
Returns
Type | Description |
---|---|
GameObject | The prefab to instantiate for each ARAnchor. |
Overrides
OnTrackablesChanged(List<ARAnchor>, List<ARAnchor>, List<ARAnchor>)
Invoked when the base class detects trackable changes.
Declaration
[Obsolete("OnTrackablesChanged() has been deprecated in AR Foundation version 6.0.", false)]
protected override void OnTrackablesChanged(List<ARAnchor> added, List<ARAnchor> updated, List<ARAnchor> removed)
Parameters
Type | Name | Description |
---|---|---|
List<ARAnchor> | added | The list of added anchors. |
List<ARAnchor> | updated | The list of updated anchors. |
List<ARAnchor> | removed | The list of removed anchors. |
Overrides
TryAddAnchorAsync(Pose)
Attempts to create a new anchor at the given pose
.
Declaration
public Awaitable<Result<ARAnchor>> TryAddAnchorAsync(Pose pose)
Parameters
Type | Name | Description |
---|---|---|
Pose | pose | The pose, in Unity world space, of the anchor. |
Returns
Type | Description |
---|---|
Awaitable<Result<ARAnchor>> | The result of the async operation. |
Examples
Use this API with C# async/await syntax as shown below:
var result = await TryAddAnchorAsync(pose);
if (result.status.IsSuccess())
DoSomethingWith(result.value);
TryEraseAnchorAsync(SerializableGuid, CancellationToken)
Attempts to erase the persistent saved data associated with an anchor given its persistent anchor GUID.
Declaration
public Awaitable<XRResultStatus> TryEraseAnchorAsync(SerializableGuid savedAnchorGuid, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
SerializableGuid | savedAnchorGuid | A persistent anchor GUID created by TrySaveAnchorAsync(ARAnchor, CancellationToken). |
CancellationToken | cancellationToken | An optional |
Returns
Type | Description |
---|---|
Awaitable<XRResultStatus> | The result of the async operation. You are responsible to await this result. |
See Also
TryGetSavedAnchorIdsAsync(Allocator, CancellationToken)
Attempts to get a NativeArray
containing all saved persistent anchor GUIDs.
Declaration
public Awaitable<Result<NativeArray<SerializableGuid>>> TryGetSavedAnchorIdsAsync(Allocator allocator, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator | The allocation strategy to use for the resulting |
CancellationToken | cancellationToken | An optional |
Returns
Type | Description |
---|---|
Awaitable<Result<NativeArray<SerializableGuid>>> | The result of the async operation, containing a |
See Also
TryLoadAnchorAsync(SerializableGuid, CancellationToken)
Attempts to load an anchor given its persistent anchor GUID.
Declaration
public Awaitable<Result<ARAnchor>> TryLoadAnchorAsync(SerializableGuid savedAnchorGuid, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
SerializableGuid | savedAnchorGuid | A persistent anchor GUID created by TrySaveAnchorAsync(ARAnchor, CancellationToken). |
CancellationToken | cancellationToken | An optional |
Returns
Type | Description |
---|---|
Awaitable<Result<ARAnchor>> | The result of the async operation, containing the newly added anchor if the operation succeeded. You are responsible to await this result. |
See Also
TryRemoveAnchor(ARAnchor)
Attempts to remove an anchor.
Declaration
public bool TryRemoveAnchor(ARAnchor anchor)
Parameters
Type | Name | Description |
---|---|---|
ARAnchor | anchor | The ARAnchor to remove. |
Returns
Type | Description |
---|---|
bool |
|
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
TrySaveAnchorAsync(ARAnchor, CancellationToken)
Attempts to persistently save the given anchor so that it can be loaded in a future AR session. Use the
SerializableGuid
returned by this method as an input parameter to TryLoadAnchorAsync(SerializableGuid, CancellationToken) or
TryEraseAnchorAsync(SerializableGuid, CancellationToken).
Declaration
public Awaitable<Result<SerializableGuid>> TrySaveAnchorAsync(ARAnchor anchor, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
ARAnchor | anchor | The anchor to save. You can create an anchor using TryAddAnchorAsync(Pose). |
CancellationToken | cancellationToken | An optional |
Returns
Type | Description |
---|---|
Awaitable<Result<SerializableGuid>> | The result of the async operation, containing a new persistent anchor GUID if the operation succeeded. You are responsible to await this result. |
See Also
Events
anchorsChanged
Invoked once per frame to communicate changes: new anchors, updates to existing anchors, and removed anchors.
Declaration
[Obsolete("anchorsChanged has been deprecated in AR Foundation version 6.0. Use trackablesChanged instead.", false)]
public event Action<ARAnchorsChangedEventArgs> anchorsChanged
Event Type
Type | Description |
---|---|
Action<ARAnchorsChangedEventArgs> |