class AnchorEntity : BaseEntity


An AnchorEntity is created to track a Pose relative to some position or surface in the "Real World." Children of this Entity will remain positioned relative to that location in the real world, for the purposes of creating Augmented Reality experiences.

Note that Anchors are only relative to the "real world", and not virtual environments. Also, calling setParent() on an AnchorEntity has no effect, as the parenting of an Anchor is controlled by the system.

Summary

Nested types

Specifies the current persist state of the Anchor.

Public functions

Anchor
getAnchor(session: Session)

Loads the ARCore for XR Anchor using a Jetpack XR Runtime session.

AnchorEntity.PersistState

Gets the current PersistState.

Int

Returns the current tracking state for this AnchorEntity.

UUID?

Requests to persist the anchor.

Unit
setOnSpaceUpdatedListener(
    listener: OnSpaceUpdatedListener?,
    executor: Executor?
)

Registers a listener to be called when the Anchor moves relative to its underlying space.

Unit
setOnStateChangedListener(
    onStateChangedListener: OnStateChangedListener?
)

Registers a listener callback to be issued when an anchor's state changes.

Inherited functions

From androidx.xr.scenecore.ActivityPose
abstract Pose

Returns the activity space pose for this ActivityPose.

abstract Pose
transformPoseTo(pose: Pose, destination: ActivityPose)

Returns a pose relative to this ActivityPose transformed into a pose relative to the destination.

From androidx.xr.scenecore.BaseEntity
open Unit
addChild(child: Entity)

Sets an Entity to be represented in this coordinate space.

open Boolean
addComponent(component: Component)

Adds a Component to this Entity.

open Unit

Disposes of any system resources held by this Entity, and transitively calls dispose() on all its children.

open Float

Returns the global alpha of this entity computed by multiplying the parent's global alpha to this entity's local alpha.

open Float

Returns the alpha transparency set for this Entity.

open List<Component>

Retrieves all components attached to this Entity.

open List<T>

Retrieves all Components of the given type T and its sub-types attached to this Entity.

open Entity?

Returns the parent of this Entity.

open Pose

Returns the pose for this entity, relative to its parent.

open Float

Returns the local scale of this entity, not inclusive of the parent's scale.

open Dimensions

Returns the dimensions (in meters) for this Entity.

open Float

Returns the accumulated scale of this Entity.

open Boolean
isHidden(includeParents: Boolean)

Returns the hidden status of this Entity.

open Unit

Remove all components from this Entity.

open Unit

Removes the given Component from this Entity.

open Unit
setAlpha(alpha: Float)

Sets the alpha transparency of the Entity and its children.

open Unit

Sets alternate text for this entity to be consumed by Accessibility systems.

open Unit
setHidden(hidden: Boolean)

Sets the local hidden state of this Entity.

open Unit
setParent(parent: Entity?)

Sets this Entity to be represented in the parent's coordinate space.

open Unit
setPose(pose: Pose)

Sets the pose for this Entity, relative to its parent.

open Unit
setScale(scale: Float)

Sets the scale of this entity relative to its parent.

open Unit
setSize(dimensions: Dimensions)

Sets the dimensions in pixels for the Entity.

Public functions

getAnchor

Added in 1.0.0-alpha01
fun getAnchor(session: Session): Anchor

Loads the ARCore for XR Anchor using a Jetpack XR Runtime session.

Parameters
session: Session

the Jetpack XR Runtime session to load the Anchor from.

Returns
Anchor

the ARCore for XR Anchor corresponding to the native pointer.

getPersistState

Added in 1.0.0-alpha01
fun getPersistState(): AnchorEntity.PersistState

Gets the current PersistState.

getState

Added in 1.0.0-alpha01
fun getState(): Int

Returns the current tracking state for this AnchorEntity.

persist

Added in 1.0.0-alpha01
fun persist(): UUID?

Requests to persist the anchor. If the anchor's State is not ANCHORED, no request will be sent and null is returned. If the request is sent successfully, returns an UUID of the anchor immediately; otherwise returns null. After this call, client should use getPersistState() to check the PersistState of the anchor. If the anchor's PersistState becomes PERSISTED before the app is closed the anchor can be recreated in a new session by calling Session.createPersistedAnchorEntity(uuid). If the PersistState doesn't become PERSISTED before the app is closed, the recreation will fail.

setOnSpaceUpdatedListener

Added in 1.0.0-alpha01
fun setOnSpaceUpdatedListener(
    listener: OnSpaceUpdatedListener?,
    executor: Executor? = null
): Unit

Registers a listener to be called when the Anchor moves relative to its underlying space.

The callback is triggered by any anchor movements such as those made by the underlying perception stack to maintain the anchor's position relative to the real world. Any cached data relative to the activity space or any other "space" should be updated when this callback is triggered.

Parameters
listener: OnSpaceUpdatedListener?

The listener to register if non-null, else stops listening if null.

executor: Executor? = null

The executor to run the listener on. Defaults to SceneCore executor if null.

setOnStateChangedListener

Added in 1.0.0-alpha01
fun setOnStateChangedListener(
    onStateChangedListener: OnStateChangedListener?
): Unit

Registers a listener callback to be issued when an anchor's state changes.