Lahfir
Lahfir

Reputation: 379

Why are gestures and hit-testing not working properly in visionOS RealityView with movement controls?

I'm building a VisionOS app with movement controls in an immersive space. The app has a main window with an ⁣ContentView and an ImmersiveSpace with ImmersiveView. I've encountered three issues:

  1. Main window UI interactions only work when .allowsHitTesting(false) is set on RealityView

  2. Movement controls in RealityView attachments aren't responding to button taps

  3. Custom gestures to toggle control visibility aren't working

My app structure:

WindowGroup {
    ContentView()
}

ImmersiveSpace(id: "immersive") {
    ImmersiveView()
}
.immersionStyle(selection: .constant(.mixed), in: .mixed)

For hit-testing:

RealityView { content, attachments in 
    // Scene setup
}
// No hit-testing modifiers anywhere in the view hierarchy
// Adding .allowsHitTesting(false) is allowing the MainView UI to work

Expected: Both main UI and RealityView interactions work Actual: Main UI doesn't respond to interactions

For movement controls:

Attachment(id: "movement_controls") {
    Button(action: { /* move forward */ }) {
        Image(systemName: "arrow.up.circle.fill")
    }
    .simultaneousGesture(
        DragGesture(minimumDistance: 0.0)
            .onChanged { _ in isMovingForward = true }
    )
}
.contentShape(Rectangle())
.allowsHitTesting(true) // Added this but still no response

Expected: Button responds to taps and moves character relative to user orientation Actual: Button doesn't respond to interactions

For visibility toggle:

VStack {
    // Movement controls
}
.gesture(TapGesture().onEnded { showControls.toggle() })

Expected: Controls toggle visibility on tap Actual: Gesture never triggers

I also tried using pressAction modifier and InputTargetComponent but buttons remain unresponsive. The controls should follow user orientation when moving.

Upvotes: 0

Views: 67

Answers (0)

Related Questions