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
- “[Worker0] Could not generate preview image“ error when opening macOS native plugin in the Inspector with Architecture to build for set to ARM 64-bit
- [iOS] Application.absoluteURL is empty on Awake/Start when opening via deep link with Splash Screen disabled
- Crash on MemoryManager::Deallocate when rapidly calling Addressables.LoadAssetAsync
- Crash on physx::shdfnd::atomicIncrement when adjusting values on a character controller component after entering Play mode in Prefab edit mode
- [Rendering Debugger] [NewInputSystem] Debug Overlays in Play mode throws InvalidOperationException when using New Input System
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();
}