| Parameter | Description |
|---|---|
| actionName | The name of the operation, which is displayed in the undo menu. |
Signals the beginning of an undoable operation.
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.
| Parameter | Description |
|---|---|
| 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. |
Signals the beginning of an undoable operation and opts specific conditions into full serialized-state capture.
Use this overload when your custom Condition subclasses expose serialized fields that you
mutate directly, for example from a ConditionView<T0> 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.
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);
}
}