Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#

StateMachine.Disconnect

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public bool Disconnect(IState fromState, IState toState);

Parameters

Parameter Description
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

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

Description

Removes all transitions that go from one state to another.

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.

Additional resources: StateMachine.GetTransitions, StateMachine.Connect

The following example removes every transition that goes from one state to another.

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