Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Disconnect(IState, IState)

Removes all transitions that go from one state to another.
Read time 1 minuteLast updated 12 days ago

Definition

public bool Disconnect(IState fromState, IState toState)

Parameters

fromState

The state the transitions originate from. Must belong to this state machine.

toState

The state the transitions go to. Must belong to this state machine.

Returns

Type

Description

bool
true
if at least one transition existed and was removed; otherwise
false
.

Remarks

Only transitions that leave
fromState
and enter
toState
are removed; transitions in the opposite direction are left untouched. When
fromState
and
toState
are the same state, self transitions on that state are removed, together with all the rules they hold. To remove a single rule and keep the transition, use ITransition.RemoveRule instead. Enclose this method with StateMachine.UndoBeginRecordStateMachine and StateMachine.UndoEndRecordStateMachine to add this operation to the undo stack and to update the graph view with the changes. Throws ArgumentNullException when
fromState
or
toState
is
null
. Throws ArgumentException when either state does not belong to this state machine.
The following example removes every transition that goes from one state to another.

Examples

void ClearTransitions(StateMachine stateMachine, IState idle, IState patrol){ stateMachine.UndoBeginRecordStateMachine("Clear transitions"); // Removes all Idle -> Patrol transitions, and returns true if there was at least one. // Patrol -> Idle transitions are left untouched. stateMachine.Disconnect(idle, patrol); // Removes the self transition on Patrol, with all the rules it holds. stateMachine.Disconnect(patrol, patrol); stateMachine.UndoEndRecordStateMachine();}