Search Issue Tracker
By Design
Unknown (hidden) 2020.3.X, 2021.3.X, 2022.1.X, 2022.2.X, 2023.1.X
Votes
0
Found in
2020.3.37f1
2021.3.9f1
2022.1.14f1
2022.2.0b5
2023.1.0a6
Issue ID
UUM-13562
Regression
No
Undo.RecordObject is not working correctly when it is applied to the members of a List
How to reproduce:
1. Open the user-attached project “BugReport”
2. Open the “main” Scene
3. Select “Main Camera” Game Object in the Hierarchy
4. Under the “Test Behaviour (Script)” Component, click the “Test” button
5. Observe the values of Integers
Expected result: All of the values are set from 0 to 9
Actual result: The Element 0-Element 6 are set to 0; others are set from 7 to 9
Reproducible with: 2020.3.37f1, 2021.3.9f1, 2022.1.14f1, 2022.2.0b5, 2023.1.0a6
Reproducible on: Windows 11 Pro
Note: On infrequent occasions, only Element 0-Element 5 are set to 0
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
- Build fails with compiler errors when switching scripts GUIDs
- Many references for Animator elements redirect to missing pages
- User gets "EndLayoutGroup: BeginLayoutGroup must be called first." error during Xcode selection canceling
- "Unable to use a named GUIStyle without a current skin" error appears in the Console when entering the Play Mode in a project with specific layout
- [D3D12][XR] SRP Foveation foveated rendering on Windows platform not working when Graphics API is set to D3D12
Resolution Note:
Hi, Undo.RecordObject works as intended. However there is a bug in your code.
What happens is when "Test" is clicked and _performTest = true is set, the if(_performTest) will occur up until there is no more objects left, and then _performTest is set to false.
If you instead separate Do and Undo into to different buttons the issue goes away.
This code should work for you:
if(GUILayout.Button("Setup"))
{
component.Integers = Enumerable.Range(0, 10).ToList();
}
if(GUILayout.Button("Do"))
{
if(component.Integers.Any())
{
Undo.IncrementCurrentGroup();
Undo.RecordObject(component, "Test");
component.Integers.RemoveAt(component.Integers.Count - 1);
Repaint();
}
}
if(GUILayout.Button("Undo"))
{
Undo.PerformUndo();
}