AnchorEntity
An anchor that tethers entities to a scene.
Declaration
@MainActor @preconcurrency class AnchorEntityMentioned in
Overview
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 target 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:
AnchorEntity(.plane(.horizontal,
classification: .any,
minimumBounds: SIMD2<Float>(0.2, 0.2)
))See Creating an anchor for more information about the different types of anchors available when using Reality Composer Pro.
[Image]
Add anchor entities directly to your scene’s anchors collection, or anywhere else in the scene hierarchy by adding them to the 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 transformMatrix(relativeTo:) 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.
[Image]
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.
An entity and its descendants can participate in the physics simulation at the root of your scene by setting its physicsSimulation to
Topics
Creating an anchor
init()init(_:)init(_:)init(_:trackingMode:)init(_:trackingMode:physicsSimulation:)init(anchor:)init(plane:classification:minimumBounds:)init(raycastResult:)init(world:)init(world:)