Class

ARAnchor

A real-world position and orientation that can be used for placing objects in an AR scene.

Overview

To track the static positions and orientations of real or virtual objects relative to the camera, create anchor objects and use the add(anchor:) method to add them to your AR session.

Some ARKit features automatically add special anchors to a session. World-tracking sessions can add ARPlaneAnchor, ARObjectAnchor, and ARImageAnchor objects if you enable the corresponding features; face-tracking sessions add ARFaceAnchor objects.

Subclassing Notes

In addition to creating your own ARAnchor instances to track the real-world positions of your virtual content, you can also subclass ARAnchor to associate custom data with anchors you create. Ensure that your anchor classes behave correctly when ARKit updates frames or saves and loads anchors in an ARWorldMap:

  • Anchor subclasses must fullfill the requirements of the NSCopying and NSSecureCoding protocols. Override copy(with:), encode(with:), and init(coder:) to copy, save, and restore the values of any custom properties your subclass adds.

  • An ARAnchor is an immutable object representing the current state of an anchor in a specific frame; when an anchor is present in more than one ARFrame, ARKit copies the ARAnchor instance on a background thread.

  • Anchors are considered equal based on their identifier property.

  • Only anchors that do not conform to ARTrackable are included when you save a world map.

Topics

Creating Custom Anchors

init(transform: simd_float4x4)

Creates a new anchor object with the specified transform.

init(name: String, transform: simd_float4x4)

Creates a new anchor object with the specified transform and a descriptive name.

Beta
var name: String?

A descriptive name for the anchor.

Beta

Tracking Anchors

var identifier: UUID

A unique identifier for the anchor.

var transform: simd_float4x4

A matrix encoding the position, orientation, and scale of the anchor relative to the world coordinate space of the AR session the anchor is placed in.

Relationships

Inherits From

See Also

Hit Testing and Real-World Positions

class ARHitTestResult

Information about a real-world surface found by examining a point in the device camera view of an AR session.

protocol ARTrackable

A real-world object in a scene for which ARKit tracks changes to position and orientation.

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