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: solution.dll
Syntax
[DefaultExecutionOrder(-2147483647)]
[DisallowMultipleComponent]
[RequireComponent(typeof(XROrigin))]
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 virtual content at a physical pose.
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.TryGetResult(out var anchor))
DoSomethingWith(anchor);
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> |