Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


UndoBeginRecordStateMachine

Signals the beginning of an undoable operation.
Read time 2 minutesLast updated 17 days ago

Definition

UndoBeginRecordStateMachine(string)

Signals the beginning of an undoable operation.
public void UndoBeginRecordStateMachine(string actionName)

Parameters

actionName

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 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.
public void UndoBeginRecordStateMachine(string actionName, params Condition[] conditionsToRecord)

Parameters

actionName

The name of the operation, which is displayed in the undo menu.

conditionsToRecord

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 subclasses expose serialized fields that you mutate directly, for example from a ConditionView<T> callback, rather than through the built-in editing controls.
Passing conditions here has two effects at StateMachine.UndoEndRecordStateMachine 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 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 overload instead.

Examples

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); }}