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

  1. 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();
    }

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.