public final class AnchorEntity extends 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

public enum AnchorEntity.PersistState extends Enum

Specifies the current persist state of the Anchor.

public static class AnchorEntity.State

Public methods

final @NonNull Anchor

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

final @NonNull AnchorEntity.PersistState

Gets the current PersistState.

final int

Returns the current tracking state for this AnchorEntity.

final UUID

Requests to persist the anchor.

final void
setOnSpaceUpdatedListener(
    OnSpaceUpdatedListener listener,
    Executor executor
)

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

final void
setOnStateChangedListener(
    OnStateChangedListener onStateChangedListener
)

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

Inherited methods

From androidx.xr.scenecore.ActivityPose
abstract @NonNull Pose

Returns the activity space pose for this ActivityPose.

abstract @NonNull Pose

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

From androidx.xr.scenecore.BaseEntity
void

Sets an Entity to be represented in this coordinate space.

boolean

Adds a Component to this Entity.

void

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

float

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

float

Returns the alpha transparency set for this Entity.

@NonNull List<@NonNull Component>

Retrieves all components attached to this Entity.

@NonNull List<@NonNull T>

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

Entity

Returns the parent of this Entity.

@NonNull Pose

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

float

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

@NonNull Dimensions

Returns the dimensions (in meters) for this Entity.

float

Returns the accumulated scale of this Entity.

boolean
isHidden(boolean includeParents)

Returns the hidden status of this Entity.

void

Remove all components from this Entity.

void

Removes the given Component from this Entity.

void
setAlpha(float alpha)

Sets the alpha transparency of the Entity and its children.

void

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

void
setHidden(boolean hidden)

Sets the local hidden state of this Entity.

void
setParent(Entity parent)

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

void

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

void
setScale(float scale)

Sets the scale of this entity relative to its parent.

void
setSize(@NonNull Dimensions dimensions)

Sets the dimensions in pixels for the Entity.

Public methods

getAnchor

Added in 1.0.0-alpha01
public final @NonNull Anchor getAnchor(@NonNull Session session)

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

Parameters
@NonNull Session session

the Jetpack XR Runtime session to load the Anchor from.

Returns
@NonNull Anchor

the ARCore for XR Anchor corresponding to the native pointer.

getPersistState

Added in 1.0.0-alpha01
public final @NonNull AnchorEntity.PersistState getPersistState()

Gets the current PersistState.

getState

Added in 1.0.0-alpha01
public final int getState()

Returns the current tracking state for this AnchorEntity.

persist

Added in 1.0.0-alpha01
public final UUID persist()

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
public final void setOnSpaceUpdatedListener(
    OnSpaceUpdatedListener listener,
    Executor executor
)

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
OnSpaceUpdatedListener listener

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

Executor executor

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

setOnStateChangedListener

Added in 1.0.0-alpha01
public final void setOnStateChangedListener(
    OnStateChangedListener onStateChangedListener
)

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