How to trigger hover events in UI in RealityView 3D space

attachments: {
         Attachment(id: "UI_Book_01") {
             Button {
               print("Tap...")
                } label: {
                   Text("Tap me")
                     .padding()
                     .background(.ultraThinMaterial)
         }.hoverEffect { effect, isActive, _ in
                if isActive {
                  print("hover...") //Unable to trigger
               }
           return effect
            }
        }
}

Hi @MaoChao

The closure passed to hoverEffect is a builder, not an event handler. SwiftUI calls it to construct the visual effect for each phase. You should return a modified effect based on isActive, not run side effects like print inside it.

Note: visionOS does not deliver gaze-hover events to your app. Eye input is private, so there is no callback that fires when people look at your view.

Fix: usehoverEffect only for visuals, and a Button action (or onTapGesture) for logic:

Button("Hover to scale") { }
    .hoverEffect { effect, isActive, _ in
        effect.scaleEffect(isActive ? 1.1 : 1.0)
    }

Thank you, can't I trigger custom feedback sound effects when hovering? Is there any other way?

How to trigger hover events in UI in RealityView 3D space
 
 
Q