Bugfix/uum 141074 fix create shape gridsnap#671
Open
lopezt-unity wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Summary of Review
There are two main issues in this PR that need to be addressed:
- Wrong Class Targeted: The fix has been applied to
PolyShapeTool(used for editing existing shapes), whereas the PR description and the new test suggest it should have been applied toDrawPolyShapeTool(used for drawing new shapes). - Ineffective Test: The new test activates
DrawPolyShapeToolinstead ofPolyShapeTooland does not actually assert thatgridSnapEnabledis enabled, meaning the test will pass even if the fix is not working.
Please review the inline feedback for details on how to resolve these issues.
🤖 Helpful? 👍/👎
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## master #671 +/- ##
==========================================
+ Coverage 36.05% 37.97% +1.91%
==========================================
Files 277 278 +1
Lines 34909 38806 +3897
==========================================
+ Hits 12588 14736 +2148
- Misses 22321 24070 +1749
Flags with carried forward coverage won't be shown. Click here to find out more.
|
…when exiting tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#Purpose of this PR
##Problem
The Create Shape tool (Cube, Sphere, Plane, etc.) was ignoring grid snapping when hovering the cursor over the scene view before starting to create a shape. Grid snapping would only activate after the first mouse click (MouseDown event). This inconsistent behavior differed from the Create PolyShape tool, which correctly snapped to the grid during hover.
Additionally, the Create PolyShape tool had gridSnapEnabled not set to true, preventing the tool from properly integrating with Unity's grid snapping system.
##Root Cause
In ShapeState_InitShape.cs, the m_IsOnGrid flag was only calculated during the MouseDown event (when clicking to start shape creation), not during hover/mouse move events. Since DrawShapeTool.GetPoint() requires both m_IsOnGrid && EditorSnapSettings.gridSnapActive to be true for snapping to work, the cursor position remained unsnapped during hover.
##Solutions
###Create Shape Tool Fix
Refactored ShapeState_InitShape.DoState() to calculate the plane and grid snapping state for ALL mouse events (hover + click), not just on MouseDown:
Key Changes:
Result: m_IsOnGrid is correctly set before GetPoint() is called during hover, enabling grid snapping throughout the shape creation workflow.
###Create PolyShape Tool Fix
Added gridSnapEnabled override to PolyShapeTool class:
public override bool gridSnapEnabled => true;This ensures the tool properly integrates with Unity's grid snapping system.
Links
Jira: https://jira.unity3d.com/browse/UUM-141074
Comments to Reviewers
[List known issues, planned work, provide any extra context for your code.]