Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Undo.RecordObjects() not affecting all objects (specifically transforms)

Discussion in 'Scripting' started by highpockets, Feb 3, 2022.

  1. highpockets

    highpockets

    Joined:
    Jan 17, 2013
    Posts:
    67
    Hello,

    The code below is producing the desired array, but Undo.RecordObjects() seems to only be affecting the _path and _path.segmentColliders objects as they are the only ones going back to their pre-edit state after an Undo. The _path.segmentColliders transforms are not reversing to their pre-edit state. It's not the end of the world, but it's not the most desirable thing happening in Unity Editor at the moment.

    Anyone, have an idea of what's happening by chance?


    Code (CSharp):
    1.  
    2. if (EditorGUI.EndChangeCheck())
    3. {
    4.     Undo.RecordObjects(
    5.         (new Object[]{_path}).Concat(
    6.             _path.segmentColliders).Concat(
    7.                 _path.segmentColliders
    8.                     .Select(collider => collider.transform)
    9.         ).ToArray(),
    10.         "Changed TraversableWaypoint"
    11.     );
    12.     _path.waypoints[i].position = new Vector2(pointHandle.x, pointHandle.y);
    13.     UpdatePathColliders();
    14. }
     
  2. highpockets

    highpockets

    Joined:
    Jan 17, 2013
    Posts:
    67
    Well, it has magically started working today without any noticeable change.. How odd.