# BoundsComponent

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/BoundsComponent.kt+class:androidx.xr.scenecore.BoundsComponent) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

*** ** * ** ***


```
public final class BoundsComponent extends Component
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.xr.scenecore.Component](https://developer.android.com/reference/androidx/xr/scenecore/Component) ||
|   | ↳ | [androidx.xr.scenecore.BoundsComponent](https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent) |

*** ** * ** ***

A component that monitors the bounds of an entity and notifies registered listeners of changes.

The bounds are represented as an axis-aligned bounding box (AABB). This component acts as a bridge to the underlying runtime, receiving bounds update events. These events are triggered whenever the entity's transformation changes, which can be caused by animations, direct pose manipulation, or changes to its parent's transformation.

**Note:** Currently, this component can only be attached to a `https://developer.android.com/reference/androidx/xr/scenecore/GltfModelEntity`. Attaching it to other entity types will fail.

To receive updates, register a `BiConsumer<Entity, BoundingBox>` listener using the `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent#addBoundsUpdateListener(java.util.concurrent.Executor,java.util.function.BiConsumer)` method. The listener will be invoked on the provided `https://developer.android.com/reference/java/util/concurrent/Executor.html`, which defaults to the main thread. Listeners should be unregistered using `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent#removeBoundsUpdateListener(java.util.function.BiConsumer)` when no longer needed to prevent resource leaks.

Create instances of this component using the `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent.Companion#create(androidx.xr.scenecore.runtime.SceneRuntime,java.util.concurrent.Executor,java.util.function.BiConsumer)` factory method.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/xr/scenecore/GltfModelEntity` |   |
| `https://developer.android.com/reference/androidx/xr/runtime/math/BoundingBox` |   |

## Summary

| ### Public methods |
|---|---|
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent#addBoundsUpdateListener(java.util.function.BiConsumer)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/function/BiConsumer.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/BoundingBox> listener )` Registers a listener that will be invoked on the main application thread for bounds updates. |
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent#addBoundsUpdateListener(java.util.concurrent.Executor,java.util.function.BiConsumer)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/function/BiConsumer.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/BoundingBox> listener )` Registers a listener to receive bounds updates. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent` | `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent#create(androidx.xr.runtime.Session)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session)` Creates a `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent`. |
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent#removeBoundsUpdateListener(java.util.function.BiConsumer)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/function/BiConsumer.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/BoundingBox> listener )` Unregisters a previously registered bounds update listener. |

| ### Protected methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent#onAttach(androidx.xr.scenecore.Entity)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity entity)` Called by the framework when this component is being added to an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |
| `void` | `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent#onDetach(androidx.xr.scenecore.Entity)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity entity)` Called by the framework when this component is being removed from an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |

## Public methods

### addBoundsUpdateListener

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

```
public final void addBoundsUpdateListener(
    @NonNull BiConsumer<@NonNull Entity, @NonNull BoundingBox> listener
)
```

Registers a listener that will be invoked on the main application thread for bounds updates.

This is a convenience overload of `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent#addBoundsUpdateListener(java.util.function.BiConsumer)` that defaults to using the main thread executor, which is useful for performing UI updates in response to bounds changes.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/function/BiConsumer.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/BoundingBox> listener` | The `BiConsumer` to be invoked with bounds updates on the main thread. |

### addBoundsUpdateListener

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

```
public final void addBoundsUpdateListener(
    @NonNull Executor executor,
    @NonNull BiConsumer<@NonNull Entity, @NonNull BoundingBox> listener
)
```

Registers a listener to receive bounds updates.

The listener's `accept(Entity, BoundingBox)` method will be invoked on the specified `https://developer.android.com/reference/java/util/concurrent/Executor.html` whenever the entity's bounds change. The updated bounds are provided as a `https://developer.android.com/reference/androidx/xr/runtime/math/BoundingBox`.

Each listener instance can only be registered once. Registering the same listener instance multiple times will have no effect.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | The executor on which the listener callbacks will be invoked. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/function/BiConsumer.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/BoundingBox> listener` | The `BiConsumer` to be invoked with the entity and its updated bounds. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent#removeBoundsUpdateListener(java.util.function.BiConsumer)` |   |

### create

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

```
public static final @NonNull BoundsComponent create(@NonNull Session session)
```

Creates a `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session` | The active `https://developer.android.com/reference/androidx/xr/runtime/Session`. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent` | A new `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent` instance. |

### removeBoundsUpdateListener

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

```
public final void removeBoundsUpdateListener(
    @NonNull BiConsumer<@NonNull Entity, @NonNull BoundingBox> listener
)
```

Unregisters a previously registered bounds update listener.

The specified listener will no longer receive bounds updates. It is important to call this method when the listener is no longer needed to prevent potential resource and memory leaks.

If the listener was not previously registered, this method has no effect.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/function/BiConsumer.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/BoundingBox> listener` | The `BiConsumer` instance to unregister. This must be the same object instance that was passed to `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent#addBoundsUpdateListener(java.util.concurrent.Executor,java.util.function.BiConsumer)`. |

## Protected methods

### onAttach

```
protected boolean onAttach(@NonNull Entity entity)
```

Called by the framework when this component is being added to an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`.

This method is triggered when `https://developer.android.com/reference/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/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)`.

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

| Returns |
|---|---|
| `boolean` | `true` if the component was successfully attached; `false` if the `https://developer.android.com/reference/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)` does not support this component or if attachment failed. |

### onDetach

```
protected void onDetach(@NonNull Entity entity)
```

Called by the framework when this component is being removed from an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`.

This method is triggered when `https://developer.android.com/reference/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/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)`.

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