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
- Inspector elements are rendered twice when the script component is added via drag-and-drop while the HideFlags.HideInInspector property is set
- Error "Light baking failed with error code 5 (Convergence data not available while rendering lightmaps)" thrown in Console when generating lighting for specific GameObjects
- Copy and Paste options for an Animation Property value are disabled in the Right click contextual menu
- Asset is not found when searching the Label "NewLabel" in Search Window
- "Compute dispatch: missing texture ID..." and "Compute dispatch: missing UAV ID..." warnings are thrown after changing the platform in High Definition 3D template
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.