Search Issue Tracker
Won't Fix
Votes
0
Found in
2017.4
2018.3.2f1
2018.4
2019.2
2019.3
2020.1
Issue ID
1198501
Regression
No
OnValidate fails to Undo the changes when one variable depends on another
How to reproduce:
1. Open attached project "UndoValidateTest.zip" and scene "TestScene"
2. In Hierarchy window, select "GameObject" object
3. Navigate to Inspector window -> "Undo Validate Test" component
4. Increase "Bevel Radius" with a mouse(click and drag to increase) to around 0.5 (the value must be higher than 0 and lower than 1 for this particular repro)
5. Decrease "Primitive Size" x variable (click and drag to decrease) to 0
6. Clear the Console window (will be easier to see how many OnValidates were called)
7. Do Undo (Ctrl + Z)
8. Observe the "Bevel Radius" value in the Inspector window
Expected result: "Bevel Radius" value is undo'ed to around 0.5 (the value set in step 4)
Actual result: "Bevel Radius" is left as 0 due to one of the OnValidate "failing" to Undo the depending variable (due to Clamping)
Reproducible with: 2017.4.35f1, 2018.4.13f1, 2019.2.13f1, 2019.3.0b11, 2020.1.0a13
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- "Shader warning in 'Hidden/Light2D': implicit truncation of vector type" is thrown when building Universal 2D template
- AI Assistant breaks compilation of packages using System.Runtime.CompilerServices.Unsafe via auto-referencing
- Unity Hub checks the "Documentation" module by default on the 6.4 and 6.5 streams despite that it was unchecked with the previous installs
- Shortcut that toggles between Dopesheet and Curves Views in the Animation Window's Timeline is mislabed
- Property List Items Overlap onto the Property List's top edge when scrolling through a long Property List
Resolution Note:
Monobehaviour.OnValidate() is being triggered before the undo action has completed. The change to BevelRadius is undone successfully and the first OnValidate validates the value change to BevelRadius only. This first call to OnValidate forces it to clamp to PrimitiveSize.X as soon as it updates. PrimitiveSize.X is still 0 as this is before undoing PrimitiveSize.X has been completed. The second OnValidate call validates the PrimitiveSize.X value change and can do nothing to change BevelRadius.
The undo actions do not know the values are dependent and therefore cannot know what order to undo their value changes. There are no current plans to be able to order the property modifications done by undo, nor to force OnValidate to wait until undo is finished.