Skip to content

Fix transform gizmo drag using stale camera / transform state#24091

Open
mufeng1991 wants to merge 2 commits intobevyengine:mainfrom
mufeng1991:fix/transform-gizmo-drag-ordering
Open

Fix transform gizmo drag using stale camera / transform state#24091
mufeng1991 wants to merge 2 commits intobevyengine:mainfrom
mufeng1991:fix/transform-gizmo-drag-ordering

Conversation

@mufeng1991
Copy link
Copy Markdown

Fix transform gizmo drag by running hover/drag after transform propagation and camera updates.

Prior ordering caused viewport_to_world to use stale camera state; also default confine_cursor to false to avoid unreliable cursor_position during drags.

Objective

  • Fix unreliable transform gizmo dragging (e.g. axis handles feeling like they “lose” input shortly after press, or the manipulated entity not tracking the cursor smoothly).
  • Align gizmo interaction with the documented contract for Camera::viewport_to_world: use an up-to-date GlobalTransform and camera computed state when casting pointer rays each frame.

Solution

  • Schedule transform_gizmo_hover and transform_gizmo_drag after TransformSystems::Propagate and CameraUpdateSystems, and run hover before drag in the same frame so hovered_axis matches the current cursor before just_pressed starts a drag.
  • transform_gizmo_hover: return early when TransformGizmoState::active before clearing hovered_axis, so drag state is not wiped at the start of the hover system while a drag is in progress.
  • TransformGizmoSettings::confine_cursor: default to false and document that CursorGrabMode::Confined can make Window::cursor_position() unreliable on some platforms, which breaks per-frame viewport_to_world during drags. Apps that want confinement can still set confine_cursor: true.

Testing

  • Ran cargo check -p bevy_gizmos.
  • Manually ran cargo run --example transform_gizmo --features free_camera (and any app using TransformGizmoPlugin): select an entity, drag translate/rotate/scale axes and view handles; confirm motion stays consistent for the whole press–drag–release cycle.
  • Reviewers: same as above; no special assets. Compare with main: if drag used to stall or jump when moving the camera (e.g. fly camera) while dragging, this branch should improve ray consistency.
  • Platforms: tested on <your OS>. Cannot test on Linux Wayland / Windows ARM / web; if anyone sees cursor issues with confine_cursor: true, that remains an opt-in path.

Migration Guide

  • If you relied on cursor confinement during gizmo drags, set transform_gizmo_settings.confine_cursor = true after plugin init (defaults are now false for robustness).

…form 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.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

Welcome, new contributor!

Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added A-Dev-Tools Tools used to debug Bevy applications. S-Needs-Review Needs reviewer attention (from anyone!) to move forward C-Refinement Improves output quality, without fixing a clear bug or adding new functionality. C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples and removed C-Refinement Improves output quality, without fixing a clear bug or adding new functionality. labels May 3, 2026
@alice-i-cecile alice-i-cecile self-requested a review May 3, 2026 17:22
Copy link
Copy Markdown
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description doesn't match the code at all. Can you please rewrite it to clearly explain your changes?

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 3, 2026
@cart cart closed this May 5, 2026
@cart cart reopened this May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Dev-Tools Tools used to debug Bevy applications. C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants