# AnchorSpace

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

*** ** * ** ***


```
class AnchorSpace : SpaceEntity
```

<br />

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

*** ** * ** ***

An AnchorSpace is a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpaceEntity` tracks a `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` relative to some position or surface in the "Real World." Children of this `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpaceEntity` will remain positioned relative to that location in the real world.

Note that, as a SpaceEntity, the AnchorSpace's position is independent of the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ActivitySpace`. It is parentless and its position and scale is controlled by the system. Calling `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpaceEntity#setPose(androidx.xr.runtime.math.Pose,androidx.xr.scenecore.Space)`, `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpaceEntity#setScale(kotlin.Float,androidx.xr.scenecore.Space)`, or setting the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#parent()` property on the AnchorSpace will result in an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html`.

AnchorSpace users must maintain a strong reference while the instance is in use. If there's no strong references to anchor instance in client code, anchor instance may become phantom reachable, and it will be garbage collected.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace.State` |

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace#create(androidx.xr.runtime.Session,androidx.xr.arcore.Anchor)(session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, anchor: https://developer.android.com/reference/kotlin/androidx/xr/arcore/Anchor)` Public factory for an AnchorSpace which uses an `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Anchor` from ARCore for Jetpack XR. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace#create(androidx.xr.runtime.Session,androidx.xr.runtime.math.FloatSize2d,kotlin.collections.Set,kotlin.collections.Set,java.time.Duration)( session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, minimumPlaneExtents: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/FloatSize2d, planeOrientations: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PlaneOrientation>, planeSemanticTypes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PlaneSemanticType>, timeout: https://developer.android.com/reference/java/time/Duration.html )` Factory for an AnchorSpace which searches for a real-world surface on which to anchor, from the set of tracked planes available to the perception system. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace#addOriginChangedListener(java.lang.Runnable)(listener: https://developer.android.com/reference/java/lang/Runnable.html)` Adds a listener to be called when the `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Anchor`'s origin moves relative to its underlying space. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace#addOriginChangedListener(java.util.concurrent.Executor,java.lang.Runnable)(executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, listener: https://developer.android.com/reference/java/lang/Runnable.html)` Adds a listener to be called when the `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Anchor`'s origin moves relative to its underlying space. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace#addStateChangedListener(java.util.function.Consumer)(listener: https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace.State>)` Adds a listener to be invoked on the main thread when the AnchorSpace's state changes. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace#addStateChangedListener(java.util.concurrent.Executor,java.util.function.Consumer)( executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, listener: https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace.State> )` Adds a listener to be invoked on the given `https://developer.android.com/reference/java/util/concurrent/Executor.html` when the AnchorSpace's state changes. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace#removeOriginChangedListener(java.lang.Runnable)(listener: https://developer.android.com/reference/java/lang/Runnable.html)` Removes the listener to be called when the `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Anchor`'s origin moves relative to its underlying space. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace#removeStateChangedListener(java.util.function.Consumer)(listener: https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace.State>)` Removes the given state changed listener. |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Anchor?` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace#anchor()` Returns the ARCore for Jetpack XR Anchor associated with this AnchorSpace. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace.State` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace#state()` The current tracking state for this AnchorSpace. |

### Inherited functions

From [androidx.xr.scenecore.BaseScenePose](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose) `open suspend https://developer.android.com/reference/kotlin/androidx/xr/scenecore/HitTestResult?` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose#hitTest(androidx.xr.runtime.math.Vector3,androidx.xr.runtime.math.Vector3)(origin: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3, direction: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3)`

Perform a hit test from the specified origin in the specified direction into the Scene.
`open suspend https://developer.android.com/reference/kotlin/androidx/xr/scenecore/HitTestResult?` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose#hitTest(androidx.xr.runtime.math.Vector3,androidx.xr.runtime.math.Vector3,kotlin.Int)(origin: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3, direction: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3, hitTestFilter: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

Creates a hit test from the specified origin in the specified direction into the scene.
`open https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose#transformDirectionTo(androidx.xr.runtime.math.Vector3,androidx.xr.scenecore.ScenePose)(direction: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3, destination: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ScenePose)`

Transforms a direction from this ScenePose's local space to the destination ScenePose's local space.
`open https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose#transformPoseTo(androidx.xr.runtime.math.Pose,androidx.xr.scenecore.ScenePose)(pose: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose, destination: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ScenePose)`

Returns a `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` relative to this ScenePose, transformed into a Pose relative to the destination.
`open https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose#transformPositionTo(androidx.xr.runtime.math.Vector3,androidx.xr.scenecore.ScenePose)(position: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3, destination: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ScenePose)`

Transforms a position from this ScenePose's local space to the destination ScenePose's local space.
`open https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose#transformVectorTo(androidx.xr.runtime.math.Vector3,androidx.xr.scenecore.ScenePose)(vector: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3, destination: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ScenePose)`

Transforms a vector from this ScenePose's local space to the destination ScenePose's local space.
From [androidx.xr.scenecore.Entity](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#addChild(androidx.xr.scenecore.Entity)(child: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity)`

Sets an Entity to be a child of this Entity in the scene graph.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)(component: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component)`

Adds a Component to this Entity.
`@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#getAlpha(androidx.xr.scenecore.Space)(relativeTo: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Space)`

Returns the alpha transparency set for this Entity, relative to given Space.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component>` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#getComponents()()`

Retrieves all components attached to this Entity.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T>` `<T : https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component> https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#getComponentsOfType(java.lang.Class)(type: https://developer.android.com/reference/java/lang/Class.html<T>)`

Retrieves all Components of the given type `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#getComponentsOfType(java.lang.Class)` and its subtypes attached to this Entity.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#isEnabled(kotlin.Boolean)(includeParents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`

Returns the enabled status of this Entity.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#removeAllComponents()()`

Remove all components from this Entity.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#removeComponent(androidx.xr.scenecore.Component)(component: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component)`

Removes the given Component from this Entity.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#setAlpha(kotlin.Float)(alpha: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`

Sets the alpha transparency of the Entity relative to the parent Space.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#setEnabled(kotlin.Boolean)(enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`

Sets the local enabled state of this Entity.
From [androidx.xr.scenecore.SpaceEntity](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpaceEntity) `open https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpaceEntity#getPose(androidx.xr.scenecore.Space)(relativeTo: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Space)`

Returns the pose of the `SpaceEntity` relative to the specified coordinate space.
`open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpaceEntity#getScale(androidx.xr.scenecore.Space)(relativeTo: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Space)`

Returns the scale of the `SpaceEntity` relative to the specified coordinate space.
`open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpaceEntity#setPose(androidx.xr.runtime.math.Pose,androidx.xr.scenecore.Space)(pose: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose, relativeTo: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Space)`

Throws `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` if called.
`open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpaceEntity#setScale(kotlin.Float,androidx.xr.scenecore.Space)(scale: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, relativeTo: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Space)`

Throws `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` if called.

### Inherited properties

From [androidx.xr.scenecore.BaseScenePose](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose) `open https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose#poseInActivitySpace()`

The current `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` relative to the activity space root.
From [androidx.xr.scenecore.Entity](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity>` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#children()`

Provides the list of all children of this entity.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#contentDescription()`

Alternate text for this Entity to be consumed by Accessibility systems.
From [androidx.xr.scenecore.SpaceEntity](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpaceEntity) `open https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity?` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SpaceEntity#parent()`

Throws `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` if called.

## Public companion functions

### create

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

```
fun create(session: Session, anchor: Anchor): AnchorSpace
```

Public factory for an AnchorSpace which uses an `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Anchor` from ARCore for Jetpack XR.

| Parameters |
|---|---|
| `session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` in which to create the AnchorSpace. |
| `anchor: https://developer.android.com/reference/kotlin/androidx/xr/arcore/Anchor` | The `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Anchor` to use for this AnchorSpace. |

### create

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

```
fun create(
    session: Session,
    minimumPlaneExtents: FloatSize2d,
    planeOrientations: Set<PlaneOrientation>,
    planeSemanticTypes: Set<PlaneSemanticType>,
    timeout: Duration = 0.seconds.toJavaDuration()
): AnchorSpace
```

Factory for an AnchorSpace which searches for a real-world surface on which to anchor, from the set of tracked planes available to the perception system.

| Parameters |
|---|---|
| `session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` in which to create the AnchorSpace. |
| `minimumPlaneExtents: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/FloatSize2d` | The minimum extents (in meters) of the plane to which this AnchorSpace should attach. |
| `planeOrientations: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PlaneOrientation>` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PlaneOrientation`s of the plane to which this AnchorSpace should attach. |
| `planeSemanticTypes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PlaneSemanticType>` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PlaneSemanticType`s of the plane to which this AnchorSpace should attach. |
| `timeout: https://developer.android.com/reference/java/time/Duration.html = 0.seconds.toJavaDuration()` | The amount of time as a `https://developer.android.com/reference/java/time/Duration.html` to search for the suitable plane to attach to. If a plane is not found within the timeout, the returned AnchorSpace state will be set to AnchorSpace.State.TIMED_OUT. It may take longer than the timeout period before the anchor state is updated. If the timeout duration is zero it will search for the anchor indefinitely. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session#config()` is set to `https://developer.android.com/reference/kotlin/androidx/xr/runtime/PlaneTrackingMode#DISABLED()`. |

## Public functions

### addOriginChangedListener

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

```
fun addOriginChangedListener(listener: Runnable): Unit
```

Adds a listener to be called when the `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Anchor`'s origin moves relative to its underlying space.

The callback is triggered on the main thread by any anchor movements, for example when the perception system moves the anchor's origin to maintain the anchor's position relative to the real world. Any cached data relative to the activity space or any other "space" should be updated when this callback is triggered. It will be automatically unregistered when the entity is disposed.

| Parameters |
|---|---|
| `listener: https://developer.android.com/reference/java/lang/Runnable.html` | The listener to register. Events will fire on the main thread. |

### addOriginChangedListener

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

```
fun addOriginChangedListener(executor: Executor, listener: Runnable): Unit
```

Adds a listener to be called when the `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Anchor`'s origin moves relative to its underlying space.

The callback is triggered on the supplied `https://developer.android.com/reference/java/util/concurrent/Executor.html` by any anchor movements, for example when the perception system moves the anchor's origin to maintain the anchor's position relative to the real world. Any cached data relative to the activity space or any other "space" should be updated when this callback is triggered. It will be automatically unregistered when the entity is disposed.

| Parameters |
|---|---|
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | The executor to run the listener on. |
| `listener: https://developer.android.com/reference/java/lang/Runnable.html` | The listener to register. |

### addStateChangedListener

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

```
fun addStateChangedListener(listener: Consumer<AnchorSpace.State>): Unit
```

Adds a listener to be invoked on the main thread when the AnchorSpace's state changes.

The listener will fire on the main thread with the current `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace.State` value immediately upon registration. It will be automatically unregistered when the entity is disposed.

### addStateChangedListener

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

```
fun addStateChangedListener(
    executor: Executor,
    listener: Consumer<AnchorSpace.State>
): Unit
```

Adds a listener to be invoked on the given `https://developer.android.com/reference/java/util/concurrent/Executor.html` when the AnchorSpace's state changes.

The listener will fire with the current State value immediately upon registration. It will be automatically unregistered when the entity is disposed.

| Parameters |
|---|---|
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | : The executor on which the specified listener will fire. |
| `listener: https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace.State>` | : The listener to fire upon invoking this method, and all subsequent state changes. |

### removeOriginChangedListener

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

```
fun removeOriginChangedListener(listener: Runnable): Unit
```

Removes the listener to be called when the `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Anchor`'s origin moves relative to its underlying space.

| Parameters |
|---|---|
| `listener: https://developer.android.com/reference/java/lang/Runnable.html` | The listener to remove. |

### removeStateChangedListener

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

```
fun removeStateChangedListener(listener: Consumer<AnchorSpace.State>): Unit
```

Removes the given state changed listener.

| Parameters |
|---|---|
| `listener: https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace.State>` | : The listener to be removed. |

## Public properties

### anchor

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

```
val anchor: Anchor?
```

Returns the ARCore for Jetpack XR Anchor associated with this AnchorSpace.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Anchor?` | the ARCore for Jetpack XR Anchor associated with this AnchorSpace. This may be null if the AnchorSpace is still searching for a suitable anchor. |

### state

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

```
val state: AnchorSpace.State
```

The current tracking state for this AnchorSpace.