Lab 092 – Manipulation from Input Target
Adding a helper function to quickly assign manipulation components to any entity with an input target component.
We have a lot of existing labs, examples, and projects that were created prior to visionOS 26. Many of these scenes already have entities configured for input in Reality Composer Pro. We’ve been using this helper to quickly add manipulation components to these entities when needed. This will find all entities in a scene that have an InputTargetComponent and add a ManipulationComponent if one is needed. This assumes these entities also have CollisionComponents (ours do).
Extension:
fileprivate extension RealityViewContent {
/// Traverses all entities in a RealityView and adds a `ManipulationComponent`
/// to any entity that already has an `InputTargetComponent` that
/// does not already have one.
func addManipulationToInputTargets() async {
await MainActor.run {
var stack = Array(self.entities)
while let entity = stack.popLast() {
if entity.components.has(InputTargetComponent.self) &&
!entity.components.has(ManipulationComponent.self) {
entity.components.set(ManipulationComponent())
}
stack.append(contentsOf: entity.children)
}
}
}
}We’ve added this to the Helpers.swift file in both our Example Code and Labs Xcode projects.
Usage:
struct Lab092: View {
var body: some View {
RealityView { content in
guard let scene = try? await Entity(named: "GestureLabs", in: realityKitContentBundle) else { return }
scene.position.y = -0.4
content.add(scene)
// The entities in this scene alread have Input Target Components that were added in Reality Composer Pro
await content.addManipulationToInputTargets()
}
}
}Support our work so we can continue to bring you new examples and articles.

Follow Step Into Vision