Why does Tap Gestures not work in Immersive View?

Hello, here is my coding for the immersive view of Xcode Beta SwiftUI VisionPro when I first create a new project.

struct ImmersiveView: View {
    @Environment(\.openWindow) var openWindow
    var body: some View {
        RealityView { content in
            // Add the initial RealityKit content
            if let immersiveContentEntity = try? await Entity(named: "Immersive", in: realityKitContentBundle) {
                content.add(immersiveContentEntity)

                // Add an ImageBasedLight for the immersive content
                guard let resource = try? await EnvironmentResource(named: "ImageBasedLight") else { return }
                let iblComponent = ImageBasedLightComponent(source: .single(resource), intensityExponent: 0.25)
                immersiveContentEntity.components.set(iblComponent)
                immersiveContentEntity.components.set(ImageBasedLightReceiverComponent(imageBasedLight: immersiveContentEntity))

                // Put skybox here.  See example in World project available at
                // https://developer.apple.com/
            }
        }
        .onLongPressGesture {
            openWindow(id:"A")
        }
    }
}

I have just added a tap gesture to the immersive view because all I want is to test and see if it opens a window by tapping anywhere on the screen in the simulator. Unfortunately, the tapping does not work but the tap gestures works in a normal window group. Please explain to me why tap gestures don't work in immersive views? I need some help. If gestures do work then can you send me the updated code with the working gesture. Thank you.

Replies

Please make sure your entity receiving the gesture has both an InputTargetComponent and CollisionComponent. See here: https://developer.apple.com/forums/thread/736007?answerId=762368022#762368022

  • I don't believe you're pointing OP in the correct direction. Here, @AngadP wants to add a gesture to the entire RealityView.

Add a Comment

Have you been able to solve this? I'm facing the same issue. I want to add a gesture recognizer to the entire RealityView, but am unable.

Hello,

Please see this thread for a solution: https://developer.apple.com/forums/thread/743623