# UndoBeginRecordStateMachine

> Signals the beginning of an undoable operation.

## Definition

* **Type:** Method
* **Namespace:** [Unity.GraphToolkit.Editor](/engine/6000.7/script-reference/unity/graphtoolkit/editor.md)
* **Assembly:** UnityEditor

## UndoBeginRecordStateMachine(string)

Signals the beginning of an undoable operation.

```csharp
public void UndoBeginRecordStateMachine(string actionName)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The name of the operation, which is displayed in the undo menu.

### Remarks

Call this before you trigger a sequence of graph modification methods to record those operations to the undo stack. Call [StateMachine.UndoEndRecordStateMachine](/engine/6000.7/script-reference/unity/graphtoolkit/editor/statemachine/undoendrecordstatemachine.md) after the sequence to signal that the operation is complete.

## UndoBeginRecordStateMachine(string, Condition\[])

Signals the beginning of an undoable operation and opts specific conditions into full serialized-state capture.

```csharp
public void UndoBeginRecordStateMachine(string actionName, params Condition[] conditionsToRecord)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The name of the operation, which is displayed in the undo menu.**** (\[Condition\[]]\(/engine/6000.7/script-reference/unity/graphtoolkit/editor/condition)): The conditions whose serialized state you plan to mutate inside this scope. Each condition must belong to this state machine.

### Remarks

Use this overload when your custom [Condition](/engine/6000.7/script-reference/unity/graphtoolkit/editor/condition.md) subclasses expose serialized fields that you mutate directly, for example from a [ConditionView\<T>](/engine/6000.7/script-reference/unity/graphtoolkit/editor/conditionview1.md) callback, rather than through the built-in editing controls.

Passing conditions here has two effects at [StateMachine.UndoEndRecordStateMachine](/engine/6000.7/script-reference/unity/graphtoolkit/editor/statemachine/undoendrecordstatemachine.md) time:

Unity's undo system captures the full serialized state of the containing state machine asset, so undo restores the previous values of your serialized fields.

The conditions are reported as changed and the state machine asset is marked dirty.

The change-notification side effects run only when the state machine is currently displayed in a graph window. From an editor script with no open window, undo capture still occurs and undo restores your serialized values as expected, but the asset is not automatically marked dirty. To persist your changes in that case, call [StateMachineDatabase.SaveStateMachine](/engine/6000.7/script-reference/unity/graphtoolkit/editor/statemachinedatabase/savestatemachine.md) explicitly.

Throws InvalidOperationException when an undo operation has already been registered to the state machine. If you only call the built-in modification methods, use the [StateMachine.UndoBeginRecordStateMachine](/engine/6000.7/script-reference/unity/graphtoolkit/editor/statemachine/undobeginrecordstatemachine.md) overload instead.

### Examples

```csharp
class HealthConditionView : ConditionView<HealthCondition>
{
    protected override bool DisplayValueField => false;

    public override void OnViewBuilt()
    {
        var slider = new Slider(0f, 100f) { value = Condition.Value };
        slider.RegisterValueChangedCallback(evt =>
        {
            // Record the write so it is undoable and marks the asset dirty.
            var stateMachine = Condition.StateMachine;
            stateMachine.UndoBeginRecordStateMachine("Change health threshold", Condition);
            Condition.Value = evt.newValue;
            stateMachine.UndoEndRecordStateMachine();
        });
        View.Root.Add(slider);
    }
}
```
