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
- Mono Windows Builds don't produce full log callstacks when generating logs
- AssetBundles fail to load when running in Built Players for Mobile Devices
- UI elements with text gets bigger and grey when Player window is moved to another screen with different resolution
- System name accepts multiline text but crops it on confirmation, duplicates input, and shrinks the field when empty
- UI element scale and position are wrong in project build when DRS is changed with HDR and Software Dynamic Resolution enabled
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.