# GetVariables

> Retrieves all variables declared in the state machine.

## Definition

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

## GetVariables()

Retrieves all variables declared in the state machine.

```csharp
public IEnumerable<IVariable> GetVariables()
```

### Returns

| Type                                                                                                       | Description                                                                                                                                 |
| ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| [IEnumerable\<IVariable>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1) | An `IEnumerable` of all [IVariable](/engine/6000.7/script-reference/unity/graphtoolkit/editor/ivariable.md)s declared in the state machine. |

### Remarks

The collection reflects the variables as declared, in their order of creation. To get the variables in a specific order, use [StateMachine.GetVariables](/engine/6000.7/script-reference/unity/graphtoolkit/editor/statemachine/getvariables.md).

## GetVariables(SortMethod)

Retrieves all variables declared in the state machine in a specific order using [SortMethod](/engine/6000.7/script-reference/unity/graphtoolkit/editor/sortmethod.md).

```csharp
public IEnumerable<IVariable> GetVariables(SortMethod sort)
```

### Parameters

**** (\[SortMethod]\(/engine/6000.7/script-reference/unity/graphtoolkit/editor/sortmethod)): The sorting method.

### Returns

| Type                                                                                                       | Description                                                                                                                                                                                                                                                   |
| ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [IEnumerable\<IVariable>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1) | An `IEnumerable` of all [IVariable](/engine/6000.7/script-reference/unity/graphtoolkit/editor/ivariable.md)s declared in the state machine, ordered using the provided [SortMethod](/engine/6000.7/script-reference/unity/graphtoolkit/editor/sortmethod.md). |

### Remarks

* The [SortMethod.Creation](/engine/6000.7/script-reference/unity/graphtoolkit/editor/sortmethod/creation.md) option returns variables in their order of creation.

* The [SortMethod.Display](/engine/6000.7/script-reference/unity/graphtoolkit/editor/sortmethod/display.md) option returns variables in the order they are displayed in the blackboard.
