Class

AnchorEntity

An anchor that tethers virtual content to a real-world object in an AR session.

Declaration

class AnchorEntity : Entity

Overview

You use an AnchorEntity instance as the root of an entity hierarchy, and add it to the anchors collection for a Scene instance. This enables ARKit to place the anchor entity, along with all of its hierarchical descendants, into the real world.

Block diagram showing how anchor entities attach to a scene, and how they support entity hierarchies.

In addition to the components the anchor entity inherits from the Entity class, the anchor entity also conforms to the HasAnchoring protocol, giving it an AnchoringComponent instance.

Diagram showing the components present in the anchor entity.

While you have only one anchor at the root of a given hierarchy of entities, you can have multiple anchors in the scene, each with its own hierarchy of entities. For example, you could have one anchor that places a toy car on a horizontal surface, like a table, and another that ties informative text bubbles to an image, all in the same scene.

Topics

Creating an Anchor

init()

Creates a new anchor entity.

init(AnchoringComponent.Target)

Creates an anchor entity targeting a particular kind of anchor.

init(anchor: ARAnchor)

Creates an anchor entity that uses an existing AR anchor.

init(raycastResult: ARRaycastResult)

Creates an anchor entity using the information about a real-world surface discovered using a ray-cast query.

init(world: float4x4)

Creates an anchor entity with a target fixed at the given position in the scene.

init(world: SIMD3<Float>)

Creates an anchor entity with a target fixed at the given position in the scene.

func clone(recursive: Bool) -> Self

Duplicates the anchor entity to create a new entity.

Identifying an Anchor

var id: ObjectIdentifier

The stable identity of the entity associated with self.

var id: UInt64

The stable identity of the anchor.

typealias AnchorEntity.ID

A type of unique identifier used for an anchor.

Configuring the Anchor

var anchoring: AnchoringComponent

The component that describes how virtual content is anchored to the real world.

struct AnchoringComponent

A description of how virtual content can be anchored to the real world.

var anchorIdentifier: UUID?

The identifier of the AR anchor with which the anchor entity is associated, or nil if it isn’t currently anchored.

func reanchor(AnchoringComponent.Target, preservingWorldTransform: Bool)

Changes the entity’s anchoring, preserving either the world transform or the local transform.

protocol HasAnchoring

An interface that enables anchoring of virtual content to a real-world object in an AR scene.

Loading a Stored Entity

Stored Entities

Manage entities stored as assets on disk.

Positioning Entities in Space

The Transform Component

Manipulate the scale, rotation, and translation of the entity.

Finding the Nearest Anchor

Calculating the Collision Shape

Describing the Anchor

See Also

Scene Elements

class ModelEntity

A representation of a physical object that RealityKit renders and optionally simulates.

Beta
class TriggerVolume

An invisible 3D shape that detects when objects enter or exit a given region of space.

Beta
class BodyTrackedEntity

An entity used to animate a virtual character in an AR scene by tracking a real person.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software