# Component

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

*** ** * ** ***


```
public abstract class Component
```

<br />

Known direct subclasses [BoundsComponent](https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent), [InteractableComponent](https://developer.android.com/reference/androidx/xr/scenecore/InteractableComponent), [MovableComponent](https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent), [PointerCaptureComponent](https://developer.android.com/reference/androidx/xr/scenecore/PointerCaptureComponent), [PositionalAudioComponent](https://developer.android.com/reference/androidx/xr/scenecore/PositionalAudioComponent), [ResizableComponent](https://developer.android.com/reference/androidx/xr/scenecore/ResizableComponent), [SoundEffectPoolComponent](https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent), [SoundFieldAudioComponent](https://developer.android.com/reference/androidx/xr/scenecore/SoundFieldAudioComponent), [SpatialPointerComponent](https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerComponent)

|---|---|
| `https://developer.android.com/reference/androidx/xr/scenecore/BoundsComponent` | A component that monitors the bounds of an entity and notifies registered listeners of changes. |
| `https://developer.android.com/reference/androidx/xr/scenecore/InteractableComponent` | Provides access to raw `https://developer.android.com/reference/androidx/xr/scenecore/InputEvent`s for given `https://developer.android.com/reference/androidx/xr/scenecore/Entity`, so a client can implement their own interaction logic. |
| `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent` | This `https://developer.android.com/reference/androidx/xr/scenecore/Component` can be attached to a single instance of an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |
| `https://developer.android.com/reference/androidx/xr/scenecore/PointerCaptureComponent` | Provides pointer capture capabilities for a given `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |
| `https://developer.android.com/reference/androidx/xr/scenecore/PositionalAudioComponent` | A Component that provides positional spatial audio playback for an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |
| `https://developer.android.com/reference/androidx/xr/scenecore/ResizableComponent` | This `https://developer.android.com/reference/androidx/xr/scenecore/Component` can be attached to a single instance of an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |
| `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent` | Provides positional sound pool audio playback for an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |
| `https://developer.android.com/reference/androidx/xr/scenecore/SoundFieldAudioComponent` | Provides spatial audio playback for a sound field associated with an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |
| `https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerComponent` | `https://developer.android.com/reference/androidx/xr/scenecore/Component` that modifies the pointer icon that is rendered on the component's `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |

*** ** * ** ***

A Component adds functionality or behaviors to an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`.

## Summary

| ### Protected methods |
|---|---|
| `abstract boolean` | `https://developer.android.com/reference/androidx/xr/scenecore/Component#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`. |
| `abstract void` | `https://developer.android.com/reference/androidx/xr/scenecore/Component#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`. |

## Protected methods

### onAttach

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

```
protected abstract 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

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

```
protected abstract 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. |