# RegisterChildrenOrderUndo(Object, string)

> Stores a copy of the order of the object's children on the undo stack.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.7/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

```csharp
public static void RegisterChildrenOrderUndo(Object objectToUndo, string name)
```

### Parameters

**** (\[Object]\(/engine/6000.7/script-reference/unityengine/object)): The object whose child order should be recorded on the undo stack.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The name of the undo operation.

### Remarks

If the undo is performed, the order of the object's children will be restored to the recorded state.

### Examples

```csharp
using UnityEngine;
using UnityEditor;

public class UndoExamples
{
    [MenuItem("Undo Examples/RegisterChildrenOrderUndo")]
    static void Example()
    {
        var parent = new GameObject("Parent");
        for (int childIndex = 0; childIndex < 5; childIndex += 1)
        {
            var child = new GameObject($"Child{childIndex}");
            child.transform.parent = parent.transform;
        }

        // Store the states of the parent object.
        Undo.RegisterChildrenOrderUndo(parent.transform, "Set as last sibling");
        parent.transform.GetChild(0).SetAsLastSibling();

        // If you choose "Edit->Undo Set as last sibling" from the main menu now, the order of the children will be restored.
    }
}
```
