# SpatialPointerComponent

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

*** ** * ** ***


```
public final class SpatialPointerComponent 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.SpatialPointerComponent](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`. If this Component is not present on an Entity the default, system-determined icon is used. Removing this Component will set the Entity's pointer back to the default icon.

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerComponent` | `https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerComponent#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 new `https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerComponent`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerIcon` | `https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerComponent#getSpatialPointerIcon()()` The `https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerIcon` that will be rendered on the component's `https://developer.android.com/reference/androidx/xr/scenecore/Entity` when the pointer is located on the entity. |
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerComponent#setSpatialPointerIcon(androidx.xr.scenecore.SpatialPointerIcon)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerIcon value)` The `https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerIcon` that will be rendered on the component's `https://developer.android.com/reference/androidx/xr/scenecore/Entity` when the pointer is located on the entity. |

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

### create

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

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

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session` | The `https://developer.android.com/reference/androidx/xr/runtime/Session` to use for creating the component. |

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

### getSpatialPointerIcon

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

```
public final @NonNull SpatialPointerIcon getSpatialPointerIcon()
```

The `https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerIcon` that will be rendered on the component's `https://developer.android.com/reference/androidx/xr/scenecore/Entity` when the pointer is located on the entity. A `https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerIcon#DEFAULT()` value indicates the default pointer icon should be used.

### setSpatialPointerIcon

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

```
public final void setSpatialPointerIcon(@NonNull SpatialPointerIcon value)
```

The `https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerIcon` that will be rendered on the component's `https://developer.android.com/reference/androidx/xr/scenecore/Entity` when the pointer is located on the entity. A `https://developer.android.com/reference/androidx/xr/scenecore/SpatialPointerIcon#DEFAULT()` value indicates the default pointer icon should be used.

## 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. |