Contents

AnchoringComponent

A component that anchors virtual content to a real world target.

Declaration

struct AnchoringComponent

Overview

This component is essential for getting AR features into RealityKit. Use AnchoringComponent to anchor virtual content to a real world target by attaching the component to any Entity in your RealityKit scene.

To create an AnchoringComponent, you need to specify a AnchoringComponent.Target. You can also specify the AnchoringComponent.TrackingMode and the AnchoringComponent.PhysicsSimulation to control how the entity tracks the anchor and how the physics simulates with the entity.

For example, here’s how to create an entity that targets the left hand’s wrist with predicted tracking mode:

let target = AnchoringComponent.Target.hand(.left, location: .wrist)
let anchoringComponent = AnchoringComponent(target, trackingMode: .predicted)
let entity = Entity()
entity.components.set(anchoringComponent)

The entity with AnchoringComponent is inactive when created. RealityKit anchors and activates the entity when it finds an anchor that meets the target requirements. You can check the entity’s anchored status using SceneEvents.AnchoredStateChanged events to receive scene events.

Similarly, RealityKit unanchors the entity if the target disappears or no longer meets the target requirements.

For more information about anchors, see ARKit.

Topics

Creating an anchoring component

Configuring the anchor

Anchor targets

Structures

See Also

Anchoring components