One Logo Pool Ball
RealityFoundation · IOS API REFERENCE

AnchorEntity

class · iOS 13.0+ · SDK 27.1

@MainActor @preconcurrency class AnchorEntity

An anchor that tethers entities to a scene. Control how RealityKit places virtual objects into your scene with anchor entities. `AnchorEntity` conforms to the ``HasAnchoring`` protocol, which gives it an ``AnchoringComponent`` instance. RealityKit places anchors based on the anchoring component's ``AnchoringComponent/target-swift.property`` property. For example, you can configure an anchor entity to rest on a horizontal surface that RealityKit detects in an AR scene like a table or floor, and RealityKit automatically places that anchor after it detects an appropriate horizontal plane in the real world. The example below creates an anchor to a horizontal surface: ```swift AnchorEntity(.plane(.horizontal, classification: .any, minimumBounds: SIMD2<Float>(0.2, 0.2) )) ``` See <doc:selecting-an-anchor-for-a-reality-composer-scene> for more information about the different types of anchors available when using Reality Composer Pro. ![A diagram showing the components present in the anchor entity. It contains three boxes labeled Transform component, Synchronization component, and Anchoring component.](AnchorEntity-1) Add anchor entities directly to your scene's ``Scene/anchors`` collection, or anywhere else in the scene hierarchy by adding them to the ``Entity/children`` collection of another entity in your scene. Because `AnchorEntity` is a subclass of ``Entity``, you can make an anchor entity a subentity of any other entity. RealityKit might move anchor entities as the scene updates, so the location and rotation of the anchor entity can change relative to its container entity, even if your code never modifies its ``Entity/transform`` property. Some anchor entities might not show up in your scene at all if RealityKit fails to detect an appropriate place for them. For example, an anchor entity with an `image` target doesn't show up in the scene until RealityKit detects the specified image in the real world. ![A block diagram showing how anchor entities attach to a scene, and how they support entity hierarchies. The root box of the hierarchy diagram represents the ARView. It has one subentity representing the ARView’s scene, and that scene has two subentities, both of which are anchor entities. Each of the anchor entities has a hierarchy of subentities beneath them, most of which are labeled Entity, but one of the entities in the hierarchy is another anchor entity.](AnchorEntity-2) You can have multiple anchors in a RealityKit scene. For example, one anchor can place a toy car on a horizontal surface, like a table, and another can tie an informative text bubble to an image in the same scene. - Note: By default, physics bodies and colliders affect only entities that share the same anchor. An entity and its descendants can participate in the physics simulation at the root of your scene by setting its ``AnchoringComponent/physicsSimulation-swift.property`` to ``AnchoringComponent/PhysicsSimulation-swift.enum/none``.

Members (7)

init · iOS 13.0+

init

TypeScript
static initPlaneClassificationMinimumBounds(alignment: AnchoringComponent_Target_Alignment, classification?: AnchoringComponent_Target_Classification, minimumBounds?: SDKHandle): Promise<AnchorEntity>
Swift declaration
@MainActor @preconcurrency convenience init(plane alignment: AnchoringComponent.Target.Alignment, classification: AnchoringComponent.Target.Classification = .any, minimumBounds: SIMD2<Float> = [0, 0])

Creates an anchor entity that targets a plane with the given characteristics. - Parameters: - alignment: The alignment of the plane to target, like ``AnchoringComponent/Target-swift.enum/Alignment/horizontal`` or ``AnchoringComponent/Target-swift.enum/Alignment/vertical``. - classification: The classification of the target plane to look for, like ``AnchoringComponent/Target-swift.enum/Classification/floor`` or ``AnchoringComponent/Target-swift.enum/Classification/ceiling``. - minimumBounds: The minimum size of the target plane.

init · iOS 13.0+

init

TypeScript
static initWorld(transform: SDKHandle): Promise<AnchorEntity>
Swift declaration
@MainActor @preconcurrency convenience init(world transform: float4x4)

Creates an anchor entity with a target fixed at the given position in the scene. - Parameters: - transform: The transform with which to initialize the world target.

init · iOS 13.0+

init

TypeScript
static initWorld83054(position: SDKHandle): Promise<AnchorEntity>
Swift declaration
@MainActor @preconcurrency convenience init(world position: SIMD3<Float>)

Creates an anchor entity with a target fixed at the given position in the scene. - Parameters: - position: The position with which to initialize the world target.

init · iOS 13.0+

init

TypeScript
static init(): Promise<AnchorEntity>
Swift declaration
@MainActor @preconcurrency required init()

Creates a new anchor entity.

init · iOS 18.0+

init

TypeScript
static initTrackingModePhysicsSimulation(target: AnchoringComponent_Target, trackingMode: AnchoringComponent_TrackingMode, physicsSimulation?: AnchoringComponent_PhysicsSimulation): Promise<AnchorEntity>
Swift declaration
@MainActor @preconcurrency convenience init(_ target: AnchoringComponent.Target, trackingMode: AnchoringComponent.TrackingMode, physicsSimulation: AnchoringComponent.PhysicsSimulation = .isolated)
init · iOS 18.0+

init

TypeScript
static initTrackingMode(target: AnchoringComponent_Target, trackingMode: AnchoringComponent_TrackingMode): Promise<AnchorEntity>
Swift declaration
@MainActor @preconcurrency convenience init(_ target: AnchoringComponent.Target, trackingMode: AnchoringComponent.TrackingMode)
init · iOS 13.0+

init

TypeScript
static init87284(target: AnchoringComponent_Target): Promise<AnchorEntity>
Swift declaration
@MainActor @preconcurrency init(_ target: AnchoringComponent.Target)

Creates an anchor entity targeting a particular kind of anchor. - Parameters: - target: The real world object the anchor should target.

Skipped declarations

No declarations were skipped in this snapshot.

All RealityFoundation types →