# Disconnect(IState, IState)

> Removes all transitions that go from one state to another.

## Definition

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

```csharp
public bool Disconnect(IState fromState, IState toState)
```

### Parameters

**** (\[IState]\(/engine/6000.7/script-reference/unity/graphtoolkit/editor/istate)): The state the transitions originate from. Must belong to this state machine.**** (\[IState]\(/engine/6000.7/script-reference/unity/graphtoolkit/editor/istate)): The state the transitions go to. Must belong to this state machine.

### Returns

| Type                                                          | Description                                                                   |
| ------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | `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](/engine/6000.7/script-reference/unity/graphtoolkit/editor/itransition/removerule.md) instead. Enclose this method with [StateMachine.UndoBeginRecordStateMachine](/engine/6000.7/script-reference/unity/graphtoolkit/editor/statemachine/undobeginrecordstatemachine.md) and [StateMachine.UndoEndRecordStateMachine](/engine/6000.7/script-reference/unity/graphtoolkit/editor/statemachine/undoendrecordstatemachine.md) 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](/engine/6000.7/script-reference/unity/graphtoolkit/editor/statemachine/gettransitions.md), [StateMachine.Connect](/engine/6000.7/script-reference/unity/graphtoolkit/editor/statemachine/connect.md)

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

### Examples

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