From 4acb34ee34d4a9b56872494ded1176d41aea15da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Tue, 24 Dec 2024 04:15:13 +0100 Subject: [PATCH] don't trigger drag events if there's no movement (#16950) # Objective - Fixes #16571 ## Solution - When position delta is zero, don't trigger `Drag` or `DragOver` events ## Testing - tested with the code from the issue --- crates/bevy_picking/src/events.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/bevy_picking/src/events.rs b/crates/bevy_picking/src/events.rs index bb2458b7af0a7..41dfa8c4b05ed 100644 --- a/crates/bevy_picking/src/events.rs +++ b/crates/bevy_picking/src/events.rs @@ -692,6 +692,10 @@ pub fn pointer_events( // Emit Drag events to the entities we are dragging for (drag_target, drag) in state.dragging.iter_mut() { + let delta = location.position - drag.latest_pos; + if delta == Vec2::ZERO { + continue; // No need to emit a Drag event if there is no movement + } let drag_event = Pointer::new( pointer_id, location.clone(), @@ -699,7 +703,7 @@ pub fn pointer_events( Drag { button, distance: location.position - drag.start_pos, - delta: location.position - drag.latest_pos, + delta, }, ); commands.trigger_targets(drag_event.clone(), *drag_target);