From 073bb94b454fe65136ea6310aebc310b0e6283c6 Mon Sep 17 00:00:00 2001 From: xiaoyao Date: Sun, 3 May 2026 11:40:11 +0800 Subject: [PATCH] Fix transform gizmo drag by running hover/drag after camera and transform propagation Prior ordering caused viewport_to_world to use stale camera state; also default confine_cursor to false to avoid unreliable cursor_position during drags. --- examples/gizmos/transform_gizmo.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/gizmos/transform_gizmo.rs b/examples/gizmos/transform_gizmo.rs index f236277abe3b0..342c64054c09c 100644 --- a/examples/gizmos/transform_gizmo.rs +++ b/examples/gizmos/transform_gizmo.rs @@ -9,7 +9,7 @@ use bevy::{ camera_controller::free_camera::{FreeCamera, FreeCameraPlugin}, gizmos::transform_gizmo::{ TransformGizmoCamera, TransformGizmoFocus, TransformGizmoMode, TransformGizmoPlugin, - TransformGizmoSettings, TransformGizmoSpace, + TransformGizmoSettings, TransformGizmoSpace, TransformGizmoState, }, picking::{pointer::PointerButton, Pickable}, prelude::*, @@ -123,10 +123,18 @@ fn on_click_select( click: On>, mut commands: Commands, existing: Query>, + gizmo_state: Res, ) { if click.button != PointerButton::Primary { return; } + // `Pointer` runs in PreUpdate; gizmo `active` is set in PostUpdate, so on the press frame + // `active` is still false while the user is grabbing an axis (`hovered_axis` is set). Mesh + // picking often resolves to geometry behind the axis and would steal `TransformGizmoFocus` + // before the drag starts. + if gizmo_state.active || gizmo_state.hovered_axis.is_some() { + return; + } // Remove focus from all entities for e in &existing { commands.entity(e).remove::();