A designer re-exports a gearbox for an Apple Vision Pro walkthrough. The housing looks the same. This time tapping it opens nothing. The person still sees one housing. What does the app see?

Here is how part selection quietly breaks. The first version identifies parts by mesh name: tap an entity, read entity.name, look up “Housing_LOD0” in a table. It works for the demo asset. Then a designer re-exports the model. The housing is now three meshes named by the export tool, the table finds nothing, and the tap does nothing. Or worse, a fastener inside the housing has a collider larger than itself, and tapping the housing selects the fastener.

Nothing failed in RealityKit. The hit test returned the entity under the person’s gaze and pinch, exactly as specified. A mesh name is an import detail, and a collider is geometry. Neither is the product’s idea of a part, and neither should be trusted to carry it.

The authority over “which part” is the assembly’s domain model. The scene only has to point back to it.

Give every interactive part a domain identity

A custom component stores the part ID on a stable part root. The input target and collision shape make that root eligible for targeted gestures. The same selection is reachable from ordinary SwiftUI controls.

SwiftGitHub
import RealityKit
import SwiftUI

enum AssemblyPart: String, CaseIterable, Identifiable, Sendable, Decodable {
    case housing = "Housing"
    case bracket = "Bracket"

    var id: Self { self }
}

struct PartIdentity: Component {
    let part: AssemblyPart
}

@main
struct AssemblyExampleApp: App {
    init() { PartIdentity.registerComponent() }

    var body: some SwiftUI.Scene {
        WindowGroup { AssemblySelectionView() }
    }
}

struct AssemblySelectionView: View {
    @State private var selection: AssemblyPart?

    var body: some View {
        VStack {
            RealityView { content in
                for (index, part) in AssemblyPart.allCases.enumerated() {
                    let size: Float = 0.08
                    let entity = ModelEntity(
                        mesh: .generateBox(size: size),
                        materials: [SimpleMaterial(color: .cyan, isMetallic: false)]
                    )
                    entity.position.x = Float(index) * 0.14 - 0.07
                    entity.components.set(PartIdentity(part: part))
                    entity.components.set(InputTargetComponent())
                    entity.components.set(HoverEffectComponent())
                    entity.components.set(CollisionComponent(shapes: [
                        .generateBox(size: SIMD3<Float>(repeating: size))
                    ]))
                    content.add(entity)
                }
            }
            .gesture(
                TapGesture().targetedToAnyEntity()
                    .onEnded { value in
                        if let part = value.entity.assemblyPart {
                            selection = part
                        }
                    }
            )

            HStack {
                ForEach(AssemblyPart.allCases) { part in
                    Button(part.rawValue) { selection = part }
                        .accessibilityAddTraits(selection == part ? .isSelected : [])
                }
            }

            if let selection {
                Text("Selected: \(selection.rawValue)")
            }
        }
    }
}

A tap on an authored asset usually lands on a leaf mesh deep inside the part, not on the part root. So identity is resolved by walking up to the nearest ancestor that carries it:

SwiftGitHub
extension Entity {
    var assemblyPart: AssemblyPart? {
        var current: Entity? = self
        while let entity = current {
            if let identity = entity.components[PartIdentity.self] {
                return identity.part
            }
            current = entity.parent
        }
        return nil
    }
}

Now the export tool can name and split meshes however it likes. As long as the part root carries PartIdentity, every leaf under it resolves to the same part. The identity is attached once, by the code that loads the assembly, from the assembly’s own manifest, never inferred from names in the asset.

A fixture that makes the problem visible

Here is a small assembly built for this edition: a housing and a bracket. This is what the person sees.

A slate-blue housing with a lid and a steel shaft, mounted against an orange L-shaped bracket held by two bolts.
The fixture assembly: two parts, a housing and a bracket.

And this is what the hit test sees. The export tool turned two parts into eight meshes and named them after the primitives they started from. None of those names means anything to the product, and the next export may renumber all of them.

The same assembly pulled apart, each of its eight meshes in a different color and labeled with its export name: Cube.001, Cube.002, Cylinder.003 and Cylinder.004 on the housing; Cube.005, Cube.006, Cylinder.007 and Cylinder.008 on the bracket.
The same assembly as the hit test sees it: eight leaf meshes with names chosen by the export tool.

The asset pipeline makes one promise, and only one: each part has a root whose path does not change between revisions. Everything below a part root is free to split, merge, and rename. The manifest that ships with the asset maps those paths to domain parts:

Plain textGitHub
{
  "assembly": "fixture-gearbox",
  "revision": 1,
  "parts": [
    { "part": "Housing", "root": "/Assembly/Housing" },
    { "part": "Bracket", "root": "/Assembly/Bracket" }
  ]
}

The loader reads the manifest, finds each part root, and attaches identity, input, and collision there. It never looks at a leaf name:

SwiftGitHub
import Foundation
import RealityKit

struct AssemblyManifest: Decodable, Sendable {
    struct Entry: Decodable, Sendable {
        let part: AssemblyPart
        let root: String            // a path the asset pipeline promises to keep
    }
    let revision: Int
    let parts: [Entry]
}

extension Entity {
    func descendant(atPath path: String) -> Entity? {
        var current: Entity? = self
        for name in path.split(separator: "/") {
            current = current?.children.first { $0.name == name }
        }
        return current
    }
}

struct LoadedAssembly {
    let root: Entity
    let missing: [AssemblyPart]
}

@MainActor
func loadAssembly(from url: URL, manifest: AssemblyManifest) async throws -> LoadedAssembly {
    let root = try await Entity(contentsOf: url)
    var missing: [AssemblyPart] = []
    for entry in manifest.parts {
        guard let partRoot = root.descendant(atPath: entry.root) else {
            missing.append(entry.part)
            continue
        }
        partRoot.components.set(PartIdentity(part: entry.part))
        partRoot.components.set(InputTargetComponent())
        partRoot.generateCollisionShapes(recursive: true)
    }
    return LoadedAssembly(root: root, missing: missing)
}

InputTargetComponent on the part root covers every mesh beneath it, and generateCollisionShapes(recursive: true) gives each leaf a shape from its own bounds, so a tap on Cylinder.007 reaches the bracket through assemblyPart. A part the manifest names but the asset no longer contains comes back in missing, which is the moment to clear a selection and say so, not a tap that silently does nothing.

The model, its manifest, and the Blender script that builds and renders it are in the examples repository. Rename the leaf meshes in Blender, export again, and the loader still resolves every tap to the right part. That is the test from the end of this edition, in miniature.

Colliders deserve the same care. Give each part a collision shape that matches its visible extent. A box that reaches over an adjacent part, or over a floating button, produces a correct hit test for the wrong interaction, and the person cannot tell why the bracket keeps selecting itself. HoverEffectComponent gives immediate visual feedback on what the system thinks is targeted, which is the fastest way to find those colliders in testing.

One selection, many presentations

The renderer may highlight the selected part or move it away from its neighbors. An inspector shows its instructions. A step list marks it. All of them observe the same selection, which is a domain value, never an entity reference. Entities are recreated when an asset reloads; a selection stored as an entity would silently point at a detached object.

For assemblies with revisions, scope the identity to the assembly and revision, and decide in advance what happens when a revision removes the selected part: clear the selection and say so, or move to the part that replaced it, if the manifest records that relationship. An asset reload should preserve a still-valid selection without preserving any mutable entity instance.

The SwiftUI buttons are not a fallback for accessibility; they are a second, equal path to the same command. They give VoiceOver and Switch Control users the workflow, they let anyone select a part hidden behind others, and they expose the current selection with the .isSelected trait. In a dense model, a readable list of parts is often faster than reaching for a small mesh, for everyone.

Test what a real hand can reach

Use a fixture asset with adjacent parts and known expected IDs. Select each part through the gesture and through the list, and assert the same detail panel updates. Replace the model with a revision that splits and renames the meshes, and repeat. That test is the one that catches mesh-name identity before a designer does.

Then put on the headset. The simulator validates identity routing and view state. Only Vision Pro can tell you whether a person can comfortably select the bracket while it is surrounded by other parts, whether the colliders match what the eye sees, and whether the instructions are readable at the distance the assembly sits.

What to ask of your own code

  • What identifies a part: the domain model, or a name the export tool chose?
  • Does a tap on any leaf mesh resolve to the part the person meant?
  • Does any collider extend beyond what the person sees?
  • Is selection stored as a domain value, so it survives an asset reload?
  • Can every part be selected without a precise pinch?

The person looking at the assembly never sees an entity hierarchy. They see a housing and a bracket, and they expect the one they chose to be the one that answers. Make the part the unit of meaning, and the scene is free to change underneath it.

References

If this edition sharpened your next review, you can buy me a coffee.