RealityKit
Create augmented reality and 3D experiences on iOS using RealityKit for rendering and ARKit for world tracking and scene understanding. Targets Swift 6.3 / iOS 26+.
Contents
Capabilities and Permissions
Add NSCameraUsageDescription to Info.plist. Add arkit to UIRequiredDeviceCapabilities only if AR is an absolute requirement for the app; otherwise, check ARWorldTrackingConfiguration.isSupported at runtime and provide a 3D fallback (content.camera = .virtual).
RealityView and Architecture
RealityView is the modern SwiftUI container for RealityKit content:
- Make closure: Asynchronously loads entities, materials, and sets up initial scene hierarchies.
- Update closure: Observes SwiftUI state changes and mutates entity properties or animations.
- Attachments: SwiftUI views anchored to 3D entities in space via
RealityViewContent.attachments.
Raycasting vs Entity Hit Testing
[!IMPORTANT]
Distinguish between real-world raycasting and virtual entity hit testing:
- ARKit Raycast (
raycast(from:allowing:alignment:)): Intersects real-world physical surfaces (floors, tables, walls) discovered by camera feature points.
- RealityKit Hit Test (
scene.hitTest(_:) / entity.hitTest(_:)): Intersects virtual 3D mesh geometry that has a CollisionComponent.
Entity-Component-System (ECS)
RealityKit uses ECS architecture:
Entity: Identity container in the 3D scene hierarchy.
Component: Pure data structs attached to entities (ModelComponent, CollisionComponent, InputTargetComponent, custom components).
System: Per-frame update logic conforming to System protocol that processes entities matching specific component sets.
Route by Task
- For loading USDZ models, custom materials, and programmatic geometries, read Entity Creation and Materials.
- For anchoring entities to planes, faces, images, or world coordinates, read Anchoring and World Tracking.
- For gesture-driven manipulation (rotate, scale, drag) and hit testing, read Gestures and Interaction.
- For physics simulations, collision detection, and raycast placement, read Physics and Raycasting.
Common Mistakes
- Missing
NSCameraUsageDescription in Info.plist, causing instant crash when RealityView initializes.
- Attempting to interact with entities that lack
CollisionComponent and InputTargetComponent.
- Loading heavy USDZ models synchronously on the main actor, dropping UI frame rates.
- Confusing virtual hit testing with ARKit real-world surface raycasting.
- Forgetting to provide a non-AR fallback (
content.camera = .virtual) for devices without world tracking.
Review Checklist
References
1---2name: realitykit3description: Build iOS augmented reality and 3D experiences with RealityKit and ARKit. Use when adding RealityView content, loading entities or USDZ models, anchoring objects to planes or world positions, distinguishing entity hit tests from ARKit real-world raycasts, handling AR camera availability, world tracking, scene updates, or RealityKit entity gestures and interactions.4---56# RealityKit78Create augmented reality and 3D experiences on iOS using RealityKit for rendering and ARKit for world tracking and scene understanding. Targets Swift 6.3 / iOS 26+.910## Contents1112- [Capabilities and Permissions](#capabilities-and-permissions)13- [RealityView and Architecture](#realityview-and-architecture)14- [Raycasting vs Entity Hit Testing](#raycasting-vs-entity-hit-testing)15- [Entity-Component-System (ECS)](#entity-component-system-ecs)16- [Route by Task](#route-by-task)17- [Common Mistakes](#common-mistakes)18- [Review Checklist](#review-checklist)19- [References](#references)2021## Capabilities and Permissions2223Add `NSCameraUsageDescription` to `Info.plist`. Add `arkit` to `UIRequiredDeviceCapabilities` only if AR is an absolute requirement for the app; otherwise, check `ARWorldTrackingConfiguration.isSupported` at runtime and provide a 3D fallback (`content.camera = .virtual`).2425## RealityView and Architecture2627`RealityView` is the modern SwiftUI container for RealityKit content:28- **Make closure**: Asynchronously loads entities, materials, and sets up initial scene hierarchies.29- **Update closure**: Observes SwiftUI state changes and mutates entity properties or animations.30- **Attachments**: SwiftUI views anchored to 3D entities in space via `RealityViewContent.attachments`.3132## Raycasting vs Entity Hit Testing3334> [!IMPORTANT]35> Distinguish between real-world raycasting and virtual entity hit testing:36> - **ARKit Raycast (`raycast(from:allowing:alignment:)`)**: Intersects real-world physical surfaces (floors, tables, walls) discovered by camera feature points.37> - **RealityKit Hit Test (`scene.hitTest(_:)` / `entity.hitTest(_:)`)**: Intersects virtual 3D mesh geometry that has a `CollisionComponent`.3839## Entity-Component-System (ECS)4041RealityKit uses ECS architecture:421. **`Entity`**: Identity container in the 3D scene hierarchy.432. **`Component`**: Pure data structs attached to entities (`ModelComponent`, `CollisionComponent`, `InputTargetComponent`, custom components).443. **`System`**: Per-frame update logic conforming to `System` protocol that processes entities matching specific component sets.4546## Route by Task4748- For loading USDZ models, custom materials, and programmatic geometries, read [Entity Creation and Materials](references/realitykit-patterns.md#entity-creation-and-materials).49- For anchoring entities to planes, faces, images, or world coordinates, read [Anchoring and World Tracking](references/realitykit-patterns.md#anchoring-and-world-tracking).50- For gesture-driven manipulation (rotate, scale, drag) and hit testing, read [Gestures and Interaction](references/realitykit-patterns.md#gestures-and-interaction).51- For physics simulations, collision detection, and raycast placement, read [Physics and Raycasting](references/realitykit-patterns.md#physics-and-raycasting).5253## Common Mistakes5455- Missing `NSCameraUsageDescription` in Info.plist, causing instant crash when `RealityView` initializes.56- Attempting to interact with entities that lack `CollisionComponent` and `InputTargetComponent`.57- Loading heavy USDZ models synchronously on the main actor, dropping UI frame rates.58- Confusing virtual hit testing with ARKit real-world surface raycasting.59- Forgetting to provide a non-AR fallback (`content.camera = .virtual`) for devices without world tracking.6061## Review Checklist6263- [ ] `NSCameraUsageDescription` declared in `Info.plist`64- [ ] Runtime support verified with `ARWorldTrackingConfiguration.isSupported`65- [ ] USDZ models and textures loaded asynchronously (`Entity(named:)` async)66- [ ] Interactive entities have both `CollisionComponent` and `InputTargetComponent`67- [ ] Real-world placement uses ARKit raycast; virtual manipulation uses entity hit test68- [ ] Per-frame system updates avoid allocating memory or performing blocking I/O69- [ ] Non-AR devices supported with virtual camera fallback7071## References7273- [RealityKit extended patterns and gesture handling](references/realitykit-patterns.md)74- [RealityKit documentation](https://sosumi.ai/documentation/realitykit)75- [RealityView](https://sosumi.ai/documentation/realitykit/realityview)76- [Entity](https://sosumi.ai/documentation/realitykit/entity)77- [ARKit documentation](https://sosumi.ai/documentation/arkit)