Search Issue Tracker
By Design
By Design in 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
- “FMOD failed to set the software format to the custom sample rate…” warnings are thrown as System Sample Rate value is being changed in Audio section of Project Settings window
- VFX Marquee selection does match the visual indicator
- “Invalid AABB aabb” errors are spammed when “Infinity” value is entered in Collider Component fields
- Editor Role does not sync with the MPPM Play Mode Scenario Role when entering Play mode
- Long asset names cause overlap with the “Find” function in search result tabs
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();
}
Resolution Note (2023.1.X):
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();
}