RealityKit visionOS Developer
Description and Goals
This skill provides comprehensive guidance for implementing RealityKit-based spatial experiences on visionOS. RealityKit uses an Entity Component System (ECS) architecture where entities are lightweight containers, behavior comes from components, and systems drive per-frame updates.
Goals
- Enable developers to build immersive 3D experiences on visionOS using RealityKit
- Provide clear guidance on when to use each component and system
- Help developers understand ECS patterns and best practices
- Support debugging and optimization of RealityKit scenes
- Ensure proper integration with SwiftUI via RealityView
What This Skill Should Do
When implementing RealityKit features on visionOS, this skill should:
- Guide component selection - Help you choose the right components for rendering, interaction, physics, audio, and animation needs
- Provide system implementation patterns - Show how to create custom systems for continuous behavior
- Offer code examples - Demonstrate common patterns like async asset loading, interactive entities, and custom systems
- Highlight best practices - Emphasize proper async loading, component registration, and performance considerations
- Warn about pitfalls - Identify common mistakes like using ARView on visionOS or blocking the main actor
Load the appropriate component or system reference file from the tables below for detailed usage, code examples, and best practices.
Information About the Skill
Core Concepts
Entities and Components
- Entities are lightweight containers; behavior comes from components.
- Prefer composition over inheritance and use custom
Component + Codable when you need per-entity state.
- Register custom components once with
Component.registerComponent() before use.
- Keep entity transforms and component updates on the main actor.
RealityView and Attachments
- Use
RealityView to bridge SwiftUI and RealityKit.
- Load assets with
Entity(named:) or Entity(contentsOf:) asynchronously and handle errors.
- Always use
ViewAttachmentComponent for SwiftUI overlays in 3D and avoid the RealityView attachments closure.
Systems and Queries
- Use a custom
System for continuous, per-frame behavior.
- Query entities with
EntityQuery + QueryPredicate and process them in update(context:).
- Use
SystemDependency to control update order when multiple systems interact.
Components Reference
Use this table to decide which component reference file to load when implementing RealityKit features:
Rendering and Appearance
| Component |
When to Use |
ModelComponent |
When rendering 3D geometry with meshes and materials on entities. |
ModelSortGroupComponent |
When experiencing depth fighting (z-fighting) issues with overlapping geometry or need to control draw order. |
OpacityComponent |
When creating fade effects, making entities semi-transparent, or implementing visibility transitions. |
AdaptiveResolutionComponent |
When optimizing performance in large scenes by reducing render quality for distant objects. |
ModelDebugOptionsComponent |
When debugging rendering issues, visualizing model geometry, or inspecting bounding boxes during development. |
MeshInstancesComponent |
When rendering many copies of the same mesh efficiently (trees, crowds, particle-like objects). |
BlendShapeWeightsComponent |
When implementing facial animation, character expressions, or morphing mesh deformations. |
User Interaction
| Component |
When to Use |
InputTargetComponent |
When making entities interactive (tappable, draggable) or handling user input events. |
ManipulationComponent |
When implementing built-in drag, rotate, and scale interactions with hand gestures or trackpad. |
GestureComponent |
When implementing custom gesture recognition beyond what ManipulationComponent provides. |
HoverEffectComponent |
When providing visual feedback when users look at or hover over interactive entities. |
AccessibilityComponent |
When making entities accessible to screen readers, VoiceOver, or other assistive technologies. |
BillboardComponent |
When creating 2D sprites, text labels, or UI elements that should always face the viewer. |
Anchoring and Spatial
| Component |
When to Use |
AnchoringComponent |
When anchoring virtual content to detected planes, tracked images, hand locations, or world targets. |
ARKitAnchorComponent |
When accessing the underlying ARKit anchor data for an anchored entity. |
SceneUnderstandingComponent |
When accessing scene understanding data like detected objects or room reconstruction. |
DockingRegionComponent |
When defining regions where content can automatically dock or snap into place. |
ReferenceComponent |
When implementing lazy loading of external entity assets or referencing entities in other files. |
AttachedTransformComponent |
When attaching an entity's transform to another entity for hierarchical positioning. |
Cameras
| Component |
When to Use |
PerspectiveCameraComponent |
When configuring a perspective camera with depth and field of view for 3D scenes. |
OrthographicCameraComponent |
When configuring an orthographic camera without perspective distortion for 2D-like views. |
ProjectiveTransformCameraComponent |
When implementing custom camera projection transforms for specialized rendering needs. |
Lighting and Shadows
| Component |
When to Use |
PointLightComponent |
When adding an omnidirectional point light that radiates in all directions from a position. |
DirectionalLightComponent |
When adding a directional light with parallel rays (like sunlight) for consistent scene lighting. |
SpotLightComponent |
When adding a cone-shaped spotlight for focused, directional lighting effects. |
ImageBasedLightComponent |
When applying environment lighting from HDR textures for realistic reflections and ambient lighting. |
ImageBasedLightReceiverComponent |
When enabling entities to receive and respond to image-based lighting in the scene. |
GroundingShadowComponent |
When adding grounding shadows to visually anchor floating content to surfaces. |
DynamicLightShadowComponent |
When enabling real-time dynamic shadows cast by light sources onto entities. |
EnvironmentLightingConfigurationComponent |
When configuring environment lighting behavior, intensity, or blending modes. |
VirtualEnvironmentProbeComponent |
When implementing reflection probes for accurate reflections in virtual environments. |
Audio
| Component |
When to Use |
SpatialAudioComponent |
When playing 3D positioned audio that changes based on listener position and orientation. |
AmbientAudioComponent |
When playing non-directional ambient audio that doesn't change with listener position. |
ChannelAudioComponent |
When playing channel-based audio content (stereo, surround, etc.) without spatialization. |
AudioLibraryComponent |
When storing and managing multiple audio resources for reuse across entities. |
ReverbComponent |
When applying reverb effects to an entity's audio for spatial acoustic simulation. |
AudioMixGroupsComponent |
When grouping audio sources for centralized mixing control and volume management. |
Animation and Character
| Component |
When to Use |
AnimationLibraryComponent |
When storing multiple animations (idle, walk, run) on a single entity for character animation. |
CharacterControllerComponent |
When implementing character movement with physics, collision, and ground detection. |
CharacterControllerStateComponent |
When storing runtime state (velocity, grounded status) for a character controller. |
SkeletalPosesComponent |
When providing skeletal pose data for skeletal animation and bone transformations. |
IKComponent |
When implementing inverse kinematics for procedural animation (e.g., reaching, pointing). |
BodyTrackingComponent |
When integrating ARKit body tracking data to animate entities based on real-world body poses. |
Physics and Collision
| Component |
When to Use |
CollisionComponent |
When defining collision shapes for hit testing, raycasting, or physics interactions. |
PhysicsBodyComponent |
When adding physical behavior (mass, gravity, forces) to entities for physics simulation. |
PhysicsMotionComponent |
When controlling linear and angular velocity of physics bodies programmatically. |
PhysicsSimulationComponent |
When configuring global physics simulation parameters like gravity or timestep. |
ParticleEmitterComponent |
When emitting particle effects (smoke, sparks, debris) from an entity position. |
ForceEffectComponent |
When applying force fields (gravity wells, explosions) that affect multiple physics bodies. |
PhysicsJointsComponent |
When creating joints (hinges, springs) between physics bodies for articulated structures. |
GeometricPinsComponent |
When defining geometric attachment points for connecting entities at specific locations. |
Portals and Environments
| Component |
When to Use |
PortalComponent |
When creating portals that render a separate world or scene through an opening. |
WorldComponent |
When designating an entity hierarchy as a separate renderable world for portal rendering. |
PortalCrossingComponent |
When controlling behavior (teleportation, scene switching) when entities cross portal boundaries. |
EnvironmentBlendingComponent |
When blending virtual content with the real environment for mixed reality experiences. |
Presentation and UI
| Component |
When to Use |
ViewAttachmentComponent |
When embedding SwiftUI views into 3D space for interactive UI elements or labels. |
PresentationComponent |
When presenting SwiftUI modals, sheets, or system UI from an entity interaction. |
TextComponent |
When rendering 3D text directly on entities without using SwiftUI views. |
ImagePresentationComponent |
When displaying images or textures on entities in 3D space. |
VideoPlayerComponent |
When playing video content on entity surfaces using AVPlayer. |
Networking and Sync
| Component |
When to Use |
SynchronizationComponent |
When synchronizing entity state, transforms, and components across networked multiplayer sessions. |
TransientComponent |
When marking entities as temporary, non-persistent, and excluded from network synchronization. |
Systems Reference
Use this reference when implementing custom ECS behavior:
| System/API |
When to Use |
System and Component Creation |
When creating custom systems for continuous, per-frame behavior or custom components for per-entity state. |
Implementation Patterns
RealityView Async Load
RealityView { content in
do {
let entity = try await Entity(named: "Scene")
content.add(entity)
} catch {
print("Failed to load entity: \(error)")
}
}
Interactive Entity Setup
let entity = ModelEntity(mesh: .generateBox(size: 0.1))
entity.components.set(CollisionComponent(shapes: [.generateBox(size: [0.1, 0.1, 0.1])]))
entity.components.set(InputTargetComponent())
entity.components.set(ManipulationComponent())
Custom System Skeleton
import RealityKit
struct SpinComponent: Component, Codable {
var speed: Float
}
struct SpinSystem: System {
static let query = EntityQuery(where: .has(SpinComponent.self))
init(scene: Scene) {}
func update(context: SceneUpdateContext) {
for entity in context.entities(matching: Self.query, updatingSystemWhen: .rendering) {
guard let spin = entity.components[SpinComponent.self] else { continue }
entity.transform.rotation *= simd_quatf(angle: spin.speed * Float(context.deltaTime), axis: [0, 1, 0])
}
}
}
SpinSystem.registerSystem()
Pitfalls and Checks
- Always load assets asynchronously; avoid blocking the main actor.
- Avoid
ARView on visionOS; use RealityView.
- Add
CollisionComponent + InputTargetComponent for draggable or tappable entities.
- Never use the
RealityView update closure; use a custom System for continuous behavior instead.
- Mesh generation is limited to
box, sphere, plane, cylinder, and cone.
1---2name: realitykit-visionos-developer3description: Build, debug, and optimize RealityKit scenes for visionOS, including entity/component setup, rendering, animation, physics, audio, input, attachments, and custom systems. Use when implementing RealityKit features or troubleshooting ECS behavior on visionOS.4---5
6# RealityKit visionOS Developer
7
8## Description and Goals
9
10This skill provides comprehensive guidance for implementing RealityKit-based spatial experiences on visionOS. RealityKit uses an Entity Component System (ECS) architecture where entities are lightweight containers, behavior comes from components, and systems drive per-frame updates.
11
12### Goals
13
14- Enable developers to build immersive 3D experiences on visionOS using RealityKit
15- Provide clear guidance on when to use each component and system
16- Help developers understand ECS patterns and best practices
17- Support debugging and optimization of RealityKit scenes
18- Ensure proper integration with SwiftUI via RealityView
19
20## What This Skill Should Do
21
22When implementing RealityKit features on visionOS, this skill should:
23
241. **Guide component selection** - Help you choose the right components for rendering, interaction, physics, audio, and animation needs
252. **Provide system implementation patterns** - Show how to create custom systems for continuous behavior
263. **Offer code examples** - Demonstrate common patterns like async asset loading, interactive entities, and custom systems
274. **Highlight best practices** - Emphasize proper async loading, component registration, and performance considerations
285. **Warn about pitfalls** - Identify common mistakes like using ARView on visionOS or blocking the main actor
29
30Load the appropriate component or system reference file from the tables below for detailed usage, code examples, and best practices.
31
32
33## Information About the Skill
34
35### Core Concepts
36
37#### Entities and Components
38
39- Entities are lightweight containers; behavior comes from components.
40- Prefer composition over inheritance and use custom `Component` + `Codable` when you need per-entity state.
41- Register custom components once with `Component.registerComponent()` before use.
42- Keep entity transforms and component updates on the main actor.
43
44#### RealityView and Attachments
45
46- Use `RealityView` to bridge SwiftUI and RealityKit.
47- Load assets with `Entity(named:)` or `Entity(contentsOf:)` asynchronously and handle errors.
48- Always use `ViewAttachmentComponent` for SwiftUI overlays in 3D and avoid the `RealityView` attachments closure.
49
50#### Systems and Queries
51
52- Use a custom `System` for continuous, per-frame behavior.
53- Query entities with `EntityQuery` + `QueryPredicate` and process them in `update(context:)`.
54- Use `SystemDependency` to control update order when multiple systems interact.
55
56### Components Reference
57
58Use this table to decide which component reference file to load when implementing RealityKit features:
59
60#### Rendering and Appearance
61
62| Component | When to Use |
63|-----------|-------------|
64| [`ModelComponent`](references/modelcomponent.md) | When rendering 3D geometry with meshes and materials on entities. |
65| [`ModelSortGroupComponent`](references/modelsortgroupcomponent.md) | When experiencing depth fighting (z-fighting) issues with overlapping geometry or need to control draw order. |
66| [`OpacityComponent`](references/opacitycomponent.md) | When creating fade effects, making entities semi-transparent, or implementing visibility transitions. |
67| [`AdaptiveResolutionComponent`](references/adaptiveresolutioncomponent.md) | When optimizing performance in large scenes by reducing render quality for distant objects. |
68| [`ModelDebugOptionsComponent`](references/modeldebugoptionscomponent.md) | When debugging rendering issues, visualizing model geometry, or inspecting bounding boxes during development. |
69| [`MeshInstancesComponent`](references/meshinstancescomponent.md) | When rendering many copies of the same mesh efficiently (trees, crowds, particle-like objects). |
70| [`BlendShapeWeightsComponent`](references/blendshapeweightscomponent.md) | When implementing facial animation, character expressions, or morphing mesh deformations. |
71
72#### User Interaction
73
74| Component | When to Use |
75|-----------|-------------|
76| [`InputTargetComponent`](references/inputtargetcomponent.md) | When making entities interactive (tappable, draggable) or handling user input events. |
77| [`ManipulationComponent`](references/manipulationcomponent.md) | When implementing built-in drag, rotate, and scale interactions with hand gestures or trackpad. |
78| [`GestureComponent`](references/gesturecomponent.md) | When implementing custom gesture recognition beyond what ManipulationComponent provides. |
79| [`HoverEffectComponent`](references/hovereffectcomponent.md) | When providing visual feedback when users look at or hover over interactive entities. |
80| [`AccessibilityComponent`](references/accessibilitycomponent.md) | When making entities accessible to screen readers, VoiceOver, or other assistive technologies. |
81| [`BillboardComponent`](references/billboardcomponent.md) | When creating 2D sprites, text labels, or UI elements that should always face the viewer. |
82
83#### Anchoring and Spatial
84
85| Component | When to Use |
86|-----------|-------------|
87| [`AnchoringComponent`](references/anchoringcomponent.md) | When anchoring virtual content to detected planes, tracked images, hand locations, or world targets. |
88| [`ARKitAnchorComponent`](references/arkitanchorcomponent.md) | When accessing the underlying ARKit anchor data for an anchored entity. |
89| [`SceneUnderstandingComponent`](references/sceneunderstandingcomponent.md) | When accessing scene understanding data like detected objects or room reconstruction. |
90| [`DockingRegionComponent`](references/dockingregioncomponent.md) | When defining regions where content can automatically dock or snap into place. |
91| [`ReferenceComponent`](references/referencecomponent.md) | When implementing lazy loading of external entity assets or referencing entities in other files. |
92| [`AttachedTransformComponent`](references/attachedtransformcomponent.md) | When attaching an entity's transform to another entity for hierarchical positioning. |
93
94#### Cameras
95
96| Component | When to Use |
97|-----------|-------------|
98| [`PerspectiveCameraComponent`](references/perspectivecameracomponent.md) | When configuring a perspective camera with depth and field of view for 3D scenes. |
99| [`OrthographicCameraComponent`](references/orthographiccameracomponent.md) | When configuring an orthographic camera without perspective distortion for 2D-like views. |
100| [`ProjectiveTransformCameraComponent`](references/projectivetransformcameracomponent.md) | When implementing custom camera projection transforms for specialized rendering needs. |
101
102#### Lighting and Shadows
103
104| Component | When to Use |
105|-----------|-------------|
106| [`PointLightComponent`](references/pointlightcomponent.md) | When adding an omnidirectional point light that radiates in all directions from a position. |
107| [`DirectionalLightComponent`](references/directionallightcomponent.md) | When adding a directional light with parallel rays (like sunlight) for consistent scene lighting. |
108| [`SpotLightComponent`](references/spotlightcomponent.md) | When adding a cone-shaped spotlight for focused, directional lighting effects. |
109| [`ImageBasedLightComponent`](references/imagebasedlightcomponent.md) | When applying environment lighting from HDR textures for realistic reflections and ambient lighting. |
110| [`ImageBasedLightReceiverComponent`](references/imagebasedlightreceivercomponent.md) | When enabling entities to receive and respond to image-based lighting in the scene. |
111| [`GroundingShadowComponent`](references/groundingshadowcomponent.md) | When adding grounding shadows to visually anchor floating content to surfaces. |
112| [`DynamicLightShadowComponent`](references/dynamiclightshadowcomponent.md) | When enabling real-time dynamic shadows cast by light sources onto entities. |
113| [`EnvironmentLightingConfigurationComponent`](references/environmentlightingconfigurationcomponent.md) | When configuring environment lighting behavior, intensity, or blending modes. |
114| [`VirtualEnvironmentProbeComponent`](references/virtualenvironmentprobecomponent.md) | When implementing reflection probes for accurate reflections in virtual environments. |
115
116#### Audio
117
118| Component | When to Use |
119|-----------|-------------|
120| [`SpatialAudioComponent`](references/spatialaudiocomponent.md) | When playing 3D positioned audio that changes based on listener position and orientation. |
121| [`AmbientAudioComponent`](references/ambientaudiocomponent.md) | When playing non-directional ambient audio that doesn't change with listener position. |
122| [`ChannelAudioComponent`](references/channelaudiocomponent.md) | When playing channel-based audio content (stereo, surround, etc.) without spatialization. |
123| [`AudioLibraryComponent`](references/audiolibrarycomponent.md) | When storing and managing multiple audio resources for reuse across entities. |
124| [`ReverbComponent`](references/reverbcomponent.md) | When applying reverb effects to an entity's audio for spatial acoustic simulation. |
125| [`AudioMixGroupsComponent`](references/audiomixgroupscomponent.md) | When grouping audio sources for centralized mixing control and volume management. |
126
127#### Animation and Character
128
129| Component | When to Use |
130|-----------|-------------|
131| [`AnimationLibraryComponent`](references/animationlibrarycomponent.md) | When storing multiple animations (idle, walk, run) on a single entity for character animation. |
132| [`CharacterControllerComponent`](references/charactercontrollercomponent.md) | When implementing character movement with physics, collision, and ground detection. |
133| [`CharacterControllerStateComponent`](references/charactercontrollerstatecomponent.md) | When storing runtime state (velocity, grounded status) for a character controller. |
134| [`SkeletalPosesComponent`](references/skeletalposescomponent.md) | When providing skeletal pose data for skeletal animation and bone transformations. |
135| [`IKComponent`](references/ikcomponent.md) | When implementing inverse kinematics for procedural animation (e.g., reaching, pointing). |
136| [`BodyTrackingComponent`](references/bodytrackingcomponent.md) | When integrating ARKit body tracking data to animate entities based on real-world body poses. |
137
138#### Physics and Collision
139
140| Component | When to Use |
141|-----------|-------------|
142| [`CollisionComponent`](references/collisioncomponent.md) | When defining collision shapes for hit testing, raycasting, or physics interactions. |
143| [`PhysicsBodyComponent`](references/physicsbodycomponent.md) | When adding physical behavior (mass, gravity, forces) to entities for physics simulation. |
144| [`PhysicsMotionComponent`](references/physicsmotioncomponent.md) | When controlling linear and angular velocity of physics bodies programmatically. |
145| [`PhysicsSimulationComponent`](references/physicssimulationcomponent.md) | When configuring global physics simulation parameters like gravity or timestep. |
146| [`ParticleEmitterComponent`](references/particleemittercomponent.md) | When emitting particle effects (smoke, sparks, debris) from an entity position. |
147| [`ForceEffectComponent`](references/forceeffectcomponent.md) | When applying force fields (gravity wells, explosions) that affect multiple physics bodies. |
148| [`PhysicsJointsComponent`](references/physicsjointscomponent.md) | When creating joints (hinges, springs) between physics bodies for articulated structures. |
149| [`GeometricPinsComponent`](references/geometricpinscomponent.md) | When defining geometric attachment points for connecting entities at specific locations. |
150
151#### Portals and Environments
152
153| Component | When to Use |
154|-----------|-------------|
155| [`PortalComponent`](references/portalcomponent.md) | When creating portals that render a separate world or scene through an opening. |
156| [`WorldComponent`](references/worldcomponent.md) | When designating an entity hierarchy as a separate renderable world for portal rendering. |
157| [`PortalCrossingComponent`](references/portalcrossingcomponent.md) | When controlling behavior (teleportation, scene switching) when entities cross portal boundaries. |
158| [`EnvironmentBlendingComponent`](references/environmentblendingcomponent.md) | When blending virtual content with the real environment for mixed reality experiences. |
159
160#### Presentation and UI
161
162| Component | When to Use |
163|-----------|-------------|
164| [`ViewAttachmentComponent`](references/viewattachmentcomponent.md) | When embedding SwiftUI views into 3D space for interactive UI elements or labels. |
165| [`PresentationComponent`](references/presentationcomponent.md) | When presenting SwiftUI modals, sheets, or system UI from an entity interaction. |
166| [`TextComponent`](references/textcomponent.md) | When rendering 3D text directly on entities without using SwiftUI views. |
167| [`ImagePresentationComponent`](references/imagepresentationcomponent.md) | When displaying images or textures on entities in 3D space. |
168| [`VideoPlayerComponent`](references/videoplayercomponent.md) | When playing video content on entity surfaces using AVPlayer. |
169
170#### Networking and Sync
171
172| Component | When to Use |
173|-----------|-------------|
174| [`SynchronizationComponent`](references/synchronizationcomponent.md) | When synchronizing entity state, transforms, and components across networked multiplayer sessions. |
175| [`TransientComponent`](references/transientcomponent.md) | When marking entities as temporary, non-persistent, and excluded from network synchronization. |
176
177### Systems Reference
178
179Use this reference when implementing custom ECS behavior:
180
181| System/API | When to Use |
182|-----------|-------------|
183| [`System and Component Creation`](references/systemandcomponentcreation.md) | When creating custom systems for continuous, per-frame behavior or custom components for per-entity state. |
184
185### Implementation Patterns
186
187#### RealityView Async Load
188
189```swift
190RealityView { content in
191 do {
192 let entity = try await Entity(named: "Scene")
193 content.add(entity)
194 } catch {
195 print("Failed to load entity: \(error)")
196 }
197}
198```
199
200#### Interactive Entity Setup
201
202```swift
203let entity = ModelEntity(mesh: .generateBox(size: 0.1))
204entity.components.set(CollisionComponent(shapes: [.generateBox(size: [0.1, 0.1, 0.1])]))
205entity.components.set(InputTargetComponent())
206entity.components.set(ManipulationComponent())
207```
208
209#### Custom System Skeleton
210
211```swift
212import RealityKit
213
214struct SpinComponent: Component, Codable {
215 var speed: Float
216}
217
218struct SpinSystem: System {
219 static let query = EntityQuery(where: .has(SpinComponent.self))
220
221 init(scene: Scene) {}
222
223 func update(context: SceneUpdateContext) {
224 for entity in context.entities(matching: Self.query, updatingSystemWhen: .rendering) {
225 guard let spin = entity.components[SpinComponent.self] else { continue }
226 entity.transform.rotation *= simd_quatf(angle: spin.speed * Float(context.deltaTime), axis: [0, 1, 0])
227 }
228 }
229}
230
231SpinSystem.registerSystem()
232```
233
234### Pitfalls and Checks
235
236- Always load assets asynchronously; avoid blocking the main actor.
237- Avoid `ARView` on visionOS; use `RealityView`.
238- Add `CollisionComponent` + `InputTargetComponent` for draggable or tappable entities.
239- Never use the `RealityView` update closure; use a custom `System` for continuous behavior instead.
240- Mesh generation is limited to `box`, `sphere`, `plane`, `cylinder`, and `cone`.