MovableComponent


class MovableComponent : Component


This Component can be attached to a single instance of an Entity. When attached, this Component will enable the user to translate the Entity by pointing and dragging on it.

Creating this Component with MovableComponent.createCustomMovable will create the Component but not move the attached Entity. It requires an EntityMoveListener which will provide suggested Poses from the system that an application can use to move the attached Entity. This should be used if the application wants to add custom logic for the Entity's movement. MovableComponent.createSystemMovable will create the Component and move the attached Entity when the user drags it to a position recommended by the system. MovableComponent.createAnchorable will create the Component, move the attached Entity when the user drags it, and also potentially reparent the Entity to a new AnchorEntity. This will occur if the user lets go of the Entity near a perception plane that matches the settings in the provided AnchorPlacement.

This component cannot be attached to an AnchorEntity or to the ActivitySpace. Calling Entity.addComponent to an Entity with these types will return false.

Summary

Public companion functions

MovableComponent
createAnchorable(
    session: Session,
    anchorPlacement: Set<AnchorPlacement>,
    disposeParentOnReAnchor: Boolean
)

Public factory function for creating a MovableComponent.

MovableComponent
createCustomMovable(
    session: Session,
    scaleInZ: Boolean,
    executor: Executor?,
    entityMoveListener: EntityMoveListener
)

Public factory function for creating a MovableComponent.

MovableComponent
createSystemMovable(session: Session, scaleInZ: Boolean)

Public factory function for creating a MovableComponent.

MovableComponent
<T : Trackable.State> createTrackingMovable(
    session: Session,
    trackable: Trackable<T>,
    poseExtractor: Function<T, Pose?>
)

Creates a MovableComponent that allows an entity's pose to be driven by an external ARCore Trackable.

Public functions

Unit
addMoveListener(entityMoveListener: EntityMoveListener)

Adds a listener to the set of active listeners for the move events.

Unit
addMoveListener(
    executor: Executor,
    entityMoveListener: EntityMoveListener
)

Adds a listener to the set of active listeners for the move events.

Unit

Removes a listener from the set of active listeners for the move events.

Protected functions

open Boolean
onAttach(entity: Entity)

Called by the framework when this component is being added to an Entity.

open Unit
onDetach(entity: Entity)

Called by the framework when this component is being removed from an Entity.

Public properties

FloatSize3d

The size of the move affordance in local space virtual meters.

Public companion functions

createAnchorable

Added in 1.0.0-alpha16
fun createAnchorable(
    session: Session,
    anchorPlacement: Set<AnchorPlacement> = setOf(AnchorPlacement.createForPlanes()),
    disposeParentOnReAnchor: Boolean = true
): MovableComponent

Public factory function for creating a MovableComponent.

This Component can be attached to a single instance of an Entity. When attached, this Component will enable the user to translate the Entity by pointing and dragging on it.

When created with this function the MovableComponent will move and potentially Anchor the Entity. When anchored a new AnchorEntity will be created and set as the parent of the Entity. If the entity is moved off of a created AnchorEntity it will be reparented to the ActivitySpace. An EntityMoveListener can be attached to receive callbacks when the Entity is being moved and to see if it was reparented to an AnchorEntity.

This component cannot be attached to an AnchorEntity or to the ActivitySpace. Calling Entity.addComponent to an Entity with these types will return false.

This functionality requires Session to be called with androidx.xr.runtime.PlaneTrackingMode.HORIZONTAL_AND_VERTICAL. This configuration requires that the SCENE_UNDERSTANDING_COARSE Android permission is granted. If not granted, the anchorable functionality will be disabled, and the element will behave as if the anchoring functionality was not applied.

Parameters
session: Session

The Session instance.

anchorPlacement: Set<AnchorPlacement> = setOf(AnchorPlacement.createForPlanes())

A Set containing different AnchorPlacement for how to anchor the Entity with a MovableComponent. When empty this Entity will not be anchored.

disposeParentOnReAnchor: Boolean = true

A Boolean, which if set to true, when an Entity is moved off of an AnchorEntity that was created by the underlying MovableComponent, and the AnchorEntity has no other children, the AnchorEntity will be disposed, and the underlying Anchor will be detached.

Returns
MovableComponent

MovableComponent instance.

Throws
IllegalArgumentException

if created with an Empty Set of for anchorPlacement

createCustomMovable

Added in 1.0.0-alpha16
fun createCustomMovable(
    session: Session,
    scaleInZ: Boolean,
    executor: Executor?,
    entityMoveListener: EntityMoveListener
): MovableComponent

Public factory function for creating a MovableComponent.

This Component can be attached to a single instance of an Entity. When attached, this Component will enable the user to translate the Entity by pointing and dragging on it.

When created with this function the MovableComponent will not move or rescale the Entity, but it could be done using the EntityMoveListener.onMoveUpdate callback.

This component cannot be attached to an AnchorEntity or to the ActivitySpace. Calling Entity.addComponent to an Entity with these types will return false.

Parameters
session: Session

The Session instance.

scaleInZ: Boolean

A Boolean which tells the system to update the scale of the Entity as the user moves it closer and further away. This is mostly useful for Panel auto-rescaling with distance.

executor: Executor?

The executor to run the listener on. If set to null, the listener will be invoked on the main thread.

entityMoveListener: EntityMoveListener

A move event listener for the event. The application should set the entity position and scale as desired using Entity.setPose and Entity.setScale in the EntityMoveListener.onMoveUpdate callback. To have the system do this movement use createSystemMovable or createAnchorable.

Returns
MovableComponent

MovableComponent instance.

createSystemMovable

Added in 1.0.0-alpha16
fun createSystemMovable(session: Session, scaleInZ: Boolean = true): MovableComponent

Public factory function for creating a MovableComponent.

This Component can be attached to a single instance of an Entity. When attached, this Component will enable the user to translate the Entity by pointing and dragging on it.

When created with this function the MovableComponent will move and rescale the Entity. EntityMoveListener can be attached to received callbacks when the Entity is being moved.

This component cannot be attached to an AnchorEntity or to the ActivitySpace. Calling Entity.addComponent to an Entity with these types will return false.

Parameters
session: Session

The Session instance.

scaleInZ: Boolean = true

A Boolean which tells the system to update the scale of the Entity as the user moves it closer and further away. This is mostly useful for Panel auto-rescaling with distance.

Returns
MovableComponent

MovableComponent instance.

createTrackingMovable

fun <T : Trackable.State> createTrackingMovable(
    session: Session,
    trackable: Trackable<T>,
    poseExtractor: Function<T, Pose?> = Function { state -> when (state) { is AugmentedObject.State -> { state.centerPose } is Eye.State -> { state.pose } is Hand.State -> { state.handJoints[HandJointType.PALM] } is Plane.State -> { state.centerPose } else -> { null } } }
): MovableComponent

Creates a MovableComponent that allows an entity's pose to be driven by an external ARCore Trackable.

This factory is designed for scenarios where an entity needs to continuously track a pose provided by an ARCore data source, such as the user's hand joint from Hand.

Once this component is created and attached to an entity, it will automatically start collecting pose updates. The collection operation is internally managed and tied to the component's attachment lifecycle. The provided poseExtractor function is invoked on the main thread during the frame update loop whenever the underlying Trackable emits a new state. This invocation begins when the component is attached to an Entity and stops when it is detached.

If the poseExtractor returns null (e.g., if a valid pose cannot be extracted from the current state), the system silently does nothing and the entity's pose remains unchanged. Note that any exceptions thrown by the poseExtractor are not caught by the runtime and will propagate, potentially crashing the application.

The default implementation of poseExtractor extracts a pose from the following states: AugmentedObject.State (using centerPose), Eye.State (using pose), Plane.State (using centerPose), and Hand.State (using the pose of the HandJointType.PALM joint). For any other state types, the default implementation returns null, resulting in no pose updates. You must provide a custom poseExtractor for unlisted types.

Parameters
<T : Trackable.State>

The type of the state emitted by the source Trackable.

session: Session

The active Session instance.

trackable: Trackable<T>

A Trackable that provides a continuous stream of state updates.

poseExtractor: Function<T, Pose?> = Function { state -> when (state) { is AugmentedObject.State -> { state.centerPose } is Eye.State -> { state.pose } is Hand.State -> { state.handJoints[HandJointType.PALM] } is Plane.State -> { state.centerPose } else -> { null } } }

A Function that extracts a nullable Pose from the given source state T.

Returns
MovableComponent

A new instance of MovableComponent configured for automatic, perception-driven movement.

Public functions

addMoveListener

Added in 1.0.0-alpha16
fun addMoveListener(entityMoveListener: EntityMoveListener): Unit

Adds a listener to the set of active listeners for the move events. The listener will be invoked regardless of whether the Entity is being moved by the system or the user.

The listener is invoked on the main thread.

Parameters
entityMoveListener: EntityMoveListener

The move event listener to set.

addMoveListener

Added in 1.0.0-alpha16
fun addMoveListener(
    executor: Executor,
    entityMoveListener: EntityMoveListener
): Unit

Adds a listener to the set of active listeners for the move events. The listener will be invoked regardless of whether the Entity is being moved by the system or the user.

The listener is invoked on the provided Executor. If the app intends to modify the UI elements/views during the callback, the app should provide the thread executor that is appropriate for the UI operations. For example, if the app is using the main thread to render the UI, the app should provide the main thread (Looper.getMainLooper()) executor. If the app is using a separate thread to render the UI, the app should provide the executor for that thread.

Parameters
executor: Executor

The executor to run the listener on.

entityMoveListener: EntityMoveListener

The move event listener to set.

removeMoveListener

Added in 1.0.0-alpha16
fun removeMoveListener(entityMoveListener: EntityMoveListener): Unit

Removes a listener from the set of active listeners for the move events.

Parameters
entityMoveListener: EntityMoveListener

The move event listener to remove.

Protected functions

onAttach

protected open fun onAttach(entity: Entity): Boolean

Called by the framework when this component is being added to an Entity.

This method is triggered when Entity.addComponent is invoked. Implementations should override this method to perform setup logic or to validate if the component is compatible with the provided entity.

Parameters
entity: Entity

The Entity to which this component is being attached.

Returns
Boolean

true if the component was successfully attached; false if the entity does not support this component or if attachment failed.

onDetach

protected open fun onDetach(entity: Entity): Unit

Called by the framework when this component is being removed from an Entity.

This method is triggered when Entity.removeComponent is invoked. Implementations should override this method to release resources or undo any changes made during onAttach.

Parameters
entity: Entity

The Entity from which this component is being detached.

Public properties

size

Added in 1.0.0-alpha16
var sizeFloatSize3d

The size of the move affordance in local space virtual meters. This property determines the size of the bounding box that is used to draw the draggable move affordances around the Entity. This property can be modified if the move affordance needs to be larger or smaller than the Entity itself.

When attaching this component to an entity, the apps may update this value to appropriate new value, such as the size of the entity this component is being added to. If apps don't set this value, the component will try to use the entity's dimensions as value for this property where applicable, or default to (1 x 1 x 1).