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

*** ** * ** ***


```
public final class AnchorSpace extends SpaceEntity
```

<br />

|---|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||||
| ↳ | [androidx.xr.scenecore.BaseScenePose](https://developer.android.com/reference/androidx/xr/scenecore/BaseScenePose) ||||
|   | ↳ | [androidx.xr.scenecore.Entity](https://developer.android.com/reference/androidx/xr/scenecore/Entity) |||
|   |   | ↳ | [androidx.xr.scenecore.SpaceEntity](https://developer.android.com/reference/androidx/xr/scenecore/SpaceEntity) ||
|   |   |   | ↳ | [androidx.xr.scenecore.AnchorSpace](https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace) |

*** ** * ** ***

An AnchorSpace is a `https://developer.android.com/reference/androidx/xr/scenecore/SpaceEntity` tracks a `https://developer.android.com/reference/androidx/xr/runtime/math/Pose` relative to some position or surface in the "Real World." Children of this `https://developer.android.com/reference/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/androidx/xr/scenecore/ActivitySpace`. It is parentless and its position and scale is controlled by the system. Calling `https://developer.android.com/reference/androidx/xr/scenecore/SpaceEntity#setPose(androidx.xr.runtime.math.Pose,androidx.xr.scenecore.Space)`, `https://developer.android.com/reference/androidx/xr/scenecore/SpaceEntity#setScale(kotlin.Float,androidx.xr.scenecore.Space)`, or setting the `https://developer.android.com/reference/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 |
|---|
| `public final class https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace.State` |

| ### Public methods |
|---|---|
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace#addOriginChangedListener(java.lang.Runnable)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Runnable.html listener)` Adds a listener to be called when the `https://developer.android.com/reference/androidx/xr/arcore/Anchor`'s origin moves relative to its underlying space. |
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace#addOriginChangedListener(java.util.concurrent.Executor,java.lang.Runnable)( @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/lang/Runnable.html listener )` Adds a listener to be called when the `https://developer.android.com/reference/androidx/xr/arcore/Anchor`'s origin moves relative to its underlying space. |
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace#addStateChangedListener(java.util.function.Consumer)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/function/Consumer.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace.State> listener )` Adds a listener to be invoked on the main thread when the AnchorSpace's state changes. |
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace#addStateChangedListener(java.util.concurrent.Executor,java.util.function.Consumer)( @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/Consumer.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace.State> listener )` 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. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace` | `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace#create(androidx.xr.runtime.Session,androidx.xr.arcore.Anchor)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/arcore/Anchor anchor)` Public factory for an AnchorSpace which uses an `https://developer.android.com/reference/androidx/xr/arcore/Anchor` from ARCore for Jetpack XR. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace` | `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace#create(androidx.xr.runtime.Session,androidx.xr.runtime.math.FloatSize2d,kotlin.collections.Set,kotlin.collections.Set,java.time.Duration)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/FloatSize2d minimumPlaneExtents, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/PlaneOrientation> planeOrientations, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/PlaneSemanticType> planeSemanticTypes, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/time/Duration.html timeout )` 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. |
| `final https://developer.android.com/reference/androidx/xr/arcore/Anchor` | `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace#getAnchor()()` Returns the ARCore for Jetpack XR Anchor associated with this AnchorSpace. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace.State` | `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace#getState()()` The current tracking state for this AnchorSpace. |
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace#removeOriginChangedListener(java.lang.Runnable)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Runnable.html listener)` Removes the listener to be called when the `https://developer.android.com/reference/androidx/xr/arcore/Anchor`'s origin moves relative to its underlying space. |
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace#removeStateChangedListener(java.util.function.Consumer)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/function/Consumer.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace.State> listener )` Removes the given state changed listener. |

### Inherited methods

From [androidx.xr.scenecore.BaseScenePose](https://developer.android.com/reference/androidx/xr/scenecore/BaseScenePose) `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Pose` `https://developer.android.com/reference/androidx/xr/scenecore/BaseScenePose#getPoseInActivitySpace()()`

The current `https://developer.android.com/reference/androidx/xr/runtime/math/Pose` relative to the activity space root.
`https://developer.android.com/reference/androidx/xr/scenecore/HitTestResult` `https://developer.android.com/reference/androidx/xr/scenecore/BaseScenePose#hitTest(androidx.xr.runtime.math.Vector3,androidx.xr.runtime.math.Vector3)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Vector3 origin, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Vector3 direction)`

Perform a hit test from the specified origin in the specified direction into the Scene.
`https://developer.android.com/reference/androidx/xr/scenecore/HitTestResult` `https://developer.android.com/reference/androidx/xr/scenecore/BaseScenePose#hitTest(androidx.xr.runtime.math.Vector3,androidx.xr.runtime.math.Vector3,kotlin.Int)(
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Vector3 origin,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Vector3 direction,
int hitTestFilter
)`

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

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

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

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

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/androidx/xr/scenecore/Entity) `final void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#addChild(androidx.xr.scenecore.Entity)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity child)`

Sets an Entity to be a child of this Entity in the scene graph.
`final boolean` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Component component)`

Adds a Component to this Entity.
`final @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#getAlpha(androidx.xr.scenecore.Space)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Space relativeTo)`

Returns the alpha transparency set for this Entity, relative to given Space.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity>` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#getChildren()()`

Provides the list of all children of this entity.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Component>` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#getComponents()()`

Retrieves all components attached to this Entity.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull T>` `<T extends https://developer.android.com/reference/androidx/xr/scenecore/Component> https://developer.android.com/reference/androidx/xr/scenecore/Entity#getComponentsOfType(java.lang.Class)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> type)`

Retrieves all Components of the given type `https://developer.android.com/reference/androidx/xr/scenecore/Entity#getComponentsOfType(java.lang.Class)` and its subtypes attached to this Entity.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#getContentDescription()()`

Alternate text for this Entity to be consumed by Accessibility systems.
`final boolean` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#isEnabled(kotlin.Boolean)(boolean includeParents)`

Returns the enabled status of this Entity.
`final void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#removeAllComponents()()`

Remove all components from this Entity.
`final void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#removeComponent(androidx.xr.scenecore.Component)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Component component)`

Removes the given Component from this Entity.
`final void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#setAlpha(kotlin.Float)(@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float alpha)`

Sets the alpha transparency of the Entity relative to the parent Space.
`final void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#setContentDescription(kotlin.CharSequence)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html value)`

Alternate text for this Entity to be consumed by Accessibility systems.
`final void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#setEnabled(kotlin.Boolean)(boolean enabled)`

Sets the local enabled state of this Entity.
From [androidx.xr.scenecore.SpaceEntity](https://developer.android.com/reference/androidx/xr/scenecore/SpaceEntity) `https://developer.android.com/reference/androidx/xr/scenecore/Entity` `https://developer.android.com/reference/androidx/xr/scenecore/SpaceEntity#getParent()()`

Throws `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` if called.
`@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Pose` `https://developer.android.com/reference/androidx/xr/scenecore/SpaceEntity#getPose(androidx.xr.scenecore.Space)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Space relativeTo)`

Returns the pose of the `SpaceEntity` relative to the specified coordinate space.
`float` `https://developer.android.com/reference/androidx/xr/scenecore/SpaceEntity#getScale(androidx.xr.scenecore.Space)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Space relativeTo)`

Returns the scale of the `SpaceEntity` relative to the specified coordinate space.
`void` `https://developer.android.com/reference/androidx/xr/scenecore/SpaceEntity#setParent(androidx.xr.scenecore.Entity)(https://developer.android.com/reference/androidx/xr/scenecore/Entity <unused var>)`

Throws `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` if called.
`void` `https://developer.android.com/reference/androidx/xr/scenecore/SpaceEntity#setPose(androidx.xr.runtime.math.Pose,androidx.xr.scenecore.Space)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Pose pose, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Space relativeTo)`

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

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

## Public methods

### addOriginChangedListener

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

```
public final void addOriginChangedListener(@NonNull Runnable listener)
```

Adds a listener to be called when the `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Runnable.html listener` | 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)

```
public final void addOriginChangedListener(
    @NonNull Executor executor,
    @NonNull Runnable listener
)
```

Adds a listener to be called when the `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | The executor to run the listener on. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Runnable.html listener` | The listener to register. |

### addStateChangedListener

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

```
public final void addStateChangedListener(
    @NonNull Consumer<@NonNull AnchorSpace.State> listener
)
```

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/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)

```
public final void addStateChangedListener(
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull AnchorSpace.State> listener
)
```

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

### create

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

```
public static final @NonNull AnchorSpace create(@NonNull Session session, @NonNull Anchor anchor)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session` | `https://developer.android.com/reference/androidx/xr/runtime/Session` in which to create the AnchorSpace. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/arcore/Anchor anchor` | The `https://developer.android.com/reference/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)

```
public static final @NonNull AnchorSpace create(
    @NonNull Session session,
    @NonNull FloatSize2d minimumPlaneExtents,
    @NonNull Set<@NonNull PlaneOrientation> planeOrientations,
    @NonNull Set<@NonNull PlaneSemanticType> planeSemanticTypes,
    @NonNull Duration timeout
)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session` | `https://developer.android.com/reference/androidx/xr/runtime/Session` in which to create the AnchorSpace. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/FloatSize2d minimumPlaneExtents` | The minimum extents (in meters) of the plane to which this AnchorSpace should attach. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/PlaneOrientation> planeOrientations` | `https://developer.android.com/reference/androidx/xr/scenecore/PlaneOrientation`s of the plane to which this AnchorSpace should attach. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/PlaneSemanticType> planeSemanticTypes` | `https://developer.android.com/reference/androidx/xr/scenecore/PlaneSemanticType`s of the plane to which this AnchorSpace should attach. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/time/Duration.html timeout` | 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/androidx/xr/runtime/Session#config()` is set to `https://developer.android.com/reference/androidx/xr/runtime/PlaneTrackingMode#DISABLED()`. |

### getAnchor

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

```
public final Anchor getAnchor()
```

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

| Returns |
|---|---|
| `https://developer.android.com/reference/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. |

### getState

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

```
public final @NonNull AnchorSpace.State getState()
```

The current tracking state for this AnchorSpace.

### removeOriginChangedListener

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

```
public final void removeOriginChangedListener(@NonNull Runnable listener)
```

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

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

### removeStateChangedListener

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

```
public final void removeStateChangedListener(
    @NonNull Consumer<@NonNull AnchorSpace.State> listener
)
```

Removes the given state changed listener.

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