# RemoveVariable(IVariable, bool)

> Removes a variable from the state machine.

## Definition

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

```csharp
public bool RemoveVariable(IVariable variable, bool forceRemove = false)
```

### Parameters

**** (\[IVariable]\(/engine/6000.7/script-reference/unity/graphtoolkit/editor/ivariable)): The variable to remove. Must belong to this graph.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): If true, removes the variable and all variable nodes referencing it. If false, removal fails if nodes exist.

### Returns

| Type                                                          | Description                                        |
| ------------------------------------------------------------- | -------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if the variable was removed; otherwise false. |

### Remarks

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.
