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
- Editor crashes when attempting to connect the client machine to the host machine
- CameraDepthTexture is flipped upside down when URP is rendering without the final blit
- Camera.current returns null when Camera.targetTexture is set to null in OnPostRender
- Crash on BaseHierarchyProperty::Next when opening a specific project
- Shader Compilation for projects with lots of Shaders can be slow (i.e. VFX Graph asset heavy projects)
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.