Just jumping in to confirm the issue that @eurobob reported. @Vision Pro Engineer suggested adding a minimalDistance, which works for me.
There is something else that could be causing issues. As we know, an Entity can only have one instance of a component type assigned at a time. Add a GestureComponent with Gesture B will overwrite a GestureComponent with Gesture A. I don't see a clear way to add more than one Gesture to a GestureComponent. The docs for this one are essentially, so no help there. Is it possible to use this component with more than one gesture?
struct Lab: View {
var body: some View {
RealityView { content in
// Load an entity and set it up for input
let subject = ModelEntity(
mesh: .generateBox(size: 0.2, cornerRadius: 0.01),
materials: [SimpleMaterial(color: .stepGreen, isMetallic: false)]
)
subject.name = "Subject"
subject.components.set(InputTargetComponent())
subject.components.set(HoverEffectComponent())
subject.components
.set(CollisionComponent(shapes: [.generateBox(width: 0.2, height: 0.2, depth: 0.2)], isStatic: false))
// This works as long as this is the only gesture we use
let gesture = DragGesture(minimumDistance: 0.001)
.onChanged({ [weak subject] _ in
print("Drag Gesture onChanged for \(subject!.name)")
})
.onEnded({ [weak subject] _ in
print("Drag Gesture onEnd for \(subject!.name)")
})
let gestureComponent = GestureComponent(gesture)
subject.components.set(gestureComponent)
let tapGesture = TapGesture()
.onEnded({ [weak subject] _ in
print("Tap Gesture Works for \(String(describing: subject))")
})
let gestureComponent2 = GestureComponent(tapGesture)
subject.components.set(gestureComponent2)
content.add(subject)
}
}
}
If I comment out the second gesture component, then the drag gesture works correctly