Anchoring Virtual Objects in iOS 12 ARKit 2
With the release of iOS 12, Apple introduced ARKit 2, which officially made it possible to anchor virtual objects to specific physical locations permanently across different app sessions. Through the introduction of persistent augmented reality experiences and world mapping features, developers gained the ability to tie digital content to real-world coordinates and restore that content in the exact same place at a later time.
How ARKit 2 Enables Persistent Anchoring
The core feature responsible for physical anchoring in ARKit 2 is the
ARWorldMap class. During an AR session, the device
continuously analyzes its surroundings, building a 3D point cloud of
feature points in the physical space.
In ARKit 2, developers can capture this point cloud along with any
active virtual anchors (ARAnchor) inside an
ARWorldMap object. This map can then be serialized into
data and saved locally on the device or shared over a network. When a
user reopens the app or another user loads the same map, ARKit compares
the camera feed with the saved feature points to relocalize the device
and place all virtual anchors back in their precise physical
locations.
Methods for Anchoring to Physical Locations
ARKit 2 provides several ways to attach virtual objects to the physical environment:
- Surface Anchors (Planes): ARKit 2 detects
horizontal surfaces (like tables and floors) as well as vertical
surfaces (like walls). Virtual objects can be locked to these planes and
preserved across sessions via
ARWorldMap. - Image Anchoring: Developers can supply reference
images (
ARReferenceImage). ARKit detects these 2D images in the real world (such as posters or signs) and immediately binds virtual objects directly to their surface and orientation. - 3D Object Anchoring: ARKit 2 introduced 3D object
detection. By scanning real-world physical objects in advance into an
ARReferenceObject, developers can trigger virtual content to anchor to distinct 3D items, such as statues or consumer products, whenever the camera recognizes them.
Multi-User Anchoring
In addition to single-user persistence, ARKit 2 uses physical
anchoring to enable shared multiplayer experiences. By transmitting the
ARWorldMap between multiple iOS devices running iOS 12,
multiple users can view and interact with the same virtual objects
anchored at identical real-world locations in real time.