Class ARTrackable<TSessionRelativeData, TTrackable>
A generic component for trackables. A "trackable" is a feature in the physical environment that can be detected and tracked by an XR device.
Inheritance
Implements
Inherited Members
Namespace: UnityEngine.XR.ARFoundation
Assembly: Unity.XR.ARFoundation.dll
Syntax
public class ARTrackable<TSessionRelativeData, TTrackable> : ARTrackable, ITrackable where TSessionRelativeData : struct, ITrackable where TTrackable : ARTrackable<TSessionRelativeData, TTrackable>
Type Parameters
Name | Description |
---|---|
TSessionRelativeData | The raw, session-relative data type used to update this trackable. |
TTrackable | The concrete class which derives from ARTrackable<TSessionRelativeData, TTrackable>. |
Properties
destroyOnRemoval
If true, this component's GameObject
will be removed immediately when the XR device reports this trackable is no longer tracked.
Declaration
public bool destroyOnRemoval { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Setting this to false will keep the GameObject
around. You might want to do this, for example,
if you have custom removal logic, such as a fade out.
nativePtr
The native pointer associated with this trackable.
Declaration
public override IntPtr nativePtr { get; }
Property Value
Type | Description |
---|---|
IntPtr | The native pointer. |
Overrides
Remarks
The data pointed to by this pointer is defined by the provider plug-in implementation. Refer to the provider documentation for each platform your app supports to learn more about the value of this pointer on your target platform(s).
pending
Pending means the trackable was added manually (usually via an AddTrackable
-style method
on its manager) but has not yet been reported as added.
Declaration
public bool pending { get; }
Property Value
Type | Description |
---|---|
bool |
pose
The Pose
, in session space, associated with this trackable.
Declaration
public override Pose pose { get; }
Property Value
Type | Description |
---|---|
Pose | The pose. |
Overrides
Examples
Some `ITrackable` implementations are MonoBehaviours, and you can use the Transform component of their GameObjects to access the position and rotation of a trackable in Unity world space. For other trackables without associated GameObjects, you can convert a session-space pose to Unity world space if needed by using the example code below, assuming the XR Origin has a uniform scale of (1, 1, 1):
var origin = FindAnyObjectByType<XROrigin>().transform;
var originPose = new Pose(origin.position, origin.rotation);
var worldSpacePose = pose.GetTransformedBy(xrOriginPose);
sessionRelativeData
The session-relative data associated with this trackable.
Declaration
protected TSessionRelativeData sessionRelativeData { get; }
Property Value
Type | Description |
---|---|
TSessionRelativeData |
trackableId
The TrackableId
associated with this trackable.
Declaration
public override TrackableId trackableId { get; }
Property Value
Type | Description |
---|---|
TrackableId | The |
Overrides
trackingState
The TrackingState
associated with this trackable.
Declaration
public override TrackingState trackingState { get; }
Property Value
Type | Description |
---|---|
TrackingState | The |
Overrides
Methods
OnAfterSetSessionRelativeData()
Invoked just after the session-relative data has been set.
The GameObject
's transform has already been updated.
You may override this method to perform further updates specific
to the derived trackable.
Declaration
protected virtual void OnAfterSetSessionRelativeData()