# MovableComponent

Artifact: [androidx.xr.scenecore:scenecore](https://developer.android.com/jetpack/androidx/releases/xr-scenecore) [View Source](https://cs.android.com/search?q=file:androidx/xr/scenecore/MovableComponent.kt+class:androidx.xr.scenecore.MovableComponent) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

*** ** * ** ***


```
class MovableComponent : Component
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.xr.scenecore.Component](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component) ||
|   | ↳ | [androidx.xr.scenecore.MovableComponent](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent) |

*** ** * ** ***

This `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component` can be attached to a single instance of an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`. When attached, this Component will enable the user to translate the Entity by pointing and dragging on it.

Creating this Component with `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent#createCustomMovable(androidx.xr.runtime.Session,kotlin.Boolean,java.util.concurrent.Executor,androidx.xr.scenecore.EntityMoveListener)` will create the Component but not move the attached Entity. It requires an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/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. `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent#createSystemMovable(androidx.xr.runtime.Session,kotlin.Boolean)` will create the Component and move the attached Entity when the user drags it to a position recommended by the system. `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent#createAnchorable(androidx.xr.runtime.Session,kotlin.collections.Set,kotlin.Boolean)` will create the Component, move the attached Entity when the user drags it, and also potentially reparent the Entity to a new `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace`. This will occur if the user lets go of the Entity near a perception plane that matches the settings in the provided `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorPlacement`.

This component cannot be attached to an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace` or to the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ActivitySpace`. Calling `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)` to an Entity with these types will return false.

## Summary

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent#createAnchorable(androidx.xr.runtime.Session,kotlin.collections.Set,kotlin.Boolean)( session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, anchorPlacement: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorPlacement>, disposeParentOnReAnchor: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Public factory function for creating a MovableComponent. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent#createCustomMovable(androidx.xr.runtime.Session,kotlin.Boolean,java.util.concurrent.Executor,androidx.xr.scenecore.EntityMoveListener)( session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, scaleInZ: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html?, entityMoveListener: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/EntityMoveListener )` Public factory function for creating a MovableComponent. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent#createSystemMovable(androidx.xr.runtime.Session,kotlin.Boolean)(session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, scaleInZ: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Public factory function for creating a MovableComponent. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent#addMoveListener(androidx.xr.scenecore.EntityMoveListener)(entityMoveListener: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/EntityMoveListener)` Adds a listener to the set of active listeners for the move events. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent#addMoveListener(java.util.concurrent.Executor,androidx.xr.scenecore.EntityMoveListener)( executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, entityMoveListener: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/EntityMoveListener )` Adds a listener to the set of active listeners for the move events. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent#removeMoveListener(androidx.xr.scenecore.EntityMoveListener)(entityMoveListener: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/EntityMoveListener)` Removes a listener from the set of active listeners for the move events. |

| ### Protected functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent#onAttach(androidx.xr.scenecore.Entity)(entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity)` Called by the framework when this component is being added to an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent#onDetach(androidx.xr.scenecore.Entity)(entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity)` Called by the framework when this component is being removed from an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`. |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/FloatSize3d` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent#size()` The size of the move affordance in local space virtual meters. |

## Public companion functions

### createAnchorable

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
fun createAnchorable(
    session: Session,
    anchorPlacement: Set<AnchorPlacement> = setOf(AnchorPlacement.createForPlanes()),
    disposeParentOnReAnchor: Boolean = true
): MovableComponent
```

Public factory function for creating a MovableComponent.

This `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component` can be attached to a single instance of an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/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 `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace` will be created and set as the parent of the Entity. If the entity is moved off of a created `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace` it will be reparented to the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ActivitySpace`. An `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/EntityMoveListener` can be attached to receive callbacks when the Entity is being moved and to see if it was reparented to an AnchorSpace.

This component cannot be attached to an AnchorSpace or to the ActivitySpace. Calling `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)` to an Entity with these types will return false.

This functionality requires `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` to be called with `https://developer.android.com/reference/kotlin/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: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | The `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` instance. |
| `anchorPlacement: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorPlacement> = setOf(AnchorPlacement.createForPlanes())` | A Set containing different `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorPlacement` for how to anchor the Entity with a MovableComponent. When empty this Entity will not be anchored. |
| `disposeParentOnReAnchor: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = true` | A Boolean, which if set to true, when an Entity is moved off of an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace` that was created by the underlying MovableComponent, and the AnchorSpace has no other children, the AnchorSpace will be disposed, and the underlying Anchor will be detached. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent` | MovableComponent instance. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if created with an Empty Set of for anchorPlacement |

### createCustomMovable

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

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

Public factory function for creating a MovableComponent.

This `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component` can be attached to a single instance of an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/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 `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/EntityMoveListener#onMoveUpdate(androidx.xr.scenecore.Entity,androidx.xr.runtime.math.Ray,androidx.xr.runtime.math.Pose,kotlin.Float)` callback.

This component cannot be attached to an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace` or to the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ActivitySpace`. Calling `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)` to an Entity with these types will return false.

| Parameters |
|---|---|
| `session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | The `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` instance. |
| `scaleInZ: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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: https://developer.android.com/reference/java/util/concurrent/Executor.html?` | The executor to run the listener on. If set to null, the listener will be invoked on the main thread. |
| `entityMoveListener: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/EntityMoveListener` | A move event listener for the event. The application should set the entity position and scale as desired using `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#setPose(androidx.xr.runtime.math.Pose,androidx.xr.scenecore.Space)` and `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#setScale(kotlin.Float,androidx.xr.scenecore.Space)` in the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/EntityMoveListener#onMoveUpdate(androidx.xr.scenecore.Entity,androidx.xr.runtime.math.Ray,androidx.xr.runtime.math.Pose,kotlin.Float)` callback. To have the system do this movement use `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent#createSystemMovable(androidx.xr.runtime.Session,kotlin.Boolean)` or `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent#createAnchorable(androidx.xr.runtime.Session,kotlin.collections.Set,kotlin.Boolean)`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent` | MovableComponent instance. |

### createSystemMovable

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
fun createSystemMovable(session: Session, scaleInZ: Boolean = true): MovableComponent
```

Public factory function for creating a MovableComponent.

This `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component` can be attached to a single instance of an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/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. `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/EntityMoveListener` can be attached to received callbacks when the Entity is being moved.

This component cannot be attached to an `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace` or to the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ActivitySpace`. Calling `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)` to an Entity with these types will return false.

| Parameters |
|---|---|
| `session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | The `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` instance. |
| `scaleInZ: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = 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 |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MovableComponent` | MovableComponent instance. |

## Public functions

### addMoveListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
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 `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` is being moved by the system or the user.

The listener is invoked on the main thread.

| Parameters |
|---|---|
| `entityMoveListener: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/EntityMoveListener` | The move event listener to set. |

### addMoveListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
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 `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` is being moved by the system or the user.

The listener is invoked on the provided `https://developer.android.com/reference/java/util/concurrent/Executor.html`. 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: https://developer.android.com/reference/java/util/concurrent/Executor.html` | The executor to run the listener on. |
| `entityMoveListener: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/EntityMoveListener` | The move event listener to set. |

### removeMoveListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
fun removeMoveListener(entityMoveListener: EntityMoveListener): Unit
```

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

| Parameters |
|---|---|
| `entityMoveListener: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/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 `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`.

This method is triggered when `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)` is invoked. Implementations should override this method to perform setup logic or to validate if the component is compatible with the provided `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)`.

| Parameters |
|---|---|
| `entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` to which this component is being attached. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the component was successfully attached; `false` if the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.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 `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`.

This method is triggered when `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#removeComponent(androidx.xr.scenecore.Component)` is invoked. Implementations should override this method to release resources or undo any changes made during `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)`.

| Parameters |
|---|---|
| `entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` from which this component is being detached. |

## Public properties

### size

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
var size: FloatSize3d
```

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 `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/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).