# GetBehaviours

> Returns all StateMachineBehaviour that match type T or are derived from T. Returns null if none are found.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.6/script-reference/unityengine.md)
* **Assembly:** UnityEngine.AnimationModule

## GetBehaviours\<T>()

Returns all [StateMachineBehaviour](/engine/6000.6/script-reference/unityengine/statemachinebehaviour.md) that match type `T` or are derived from `T`. Returns null if none are found.

```csharp
public T[] GetBehaviours<T>() where T : StateMachineBehaviour
```

### Returns

| Type              | Description |
| ----------------- | ----------- |
| [\<T>\[\]](./.md) |             |

### Examples

```csharp
using UnityEngine;
using System.Collections;

// An example StateMachineBehaviour.
public class BreathBehaviour : StateMachineBehaviour
{
    public bool  fastBreath;

    // OnStateUpdate is called at each Update frame between OnStateEnter and OnStateExit callback
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        animator.SetBool("FastBreath", fastBreath);
    }
}


public class RunBehaviour : StateMachineBehaviour
{
    // OnStateUpdate is called at each Update frame between OnStateEnter and OnStateExit callback
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        BreathBehaviour[] breathBehaviours = animator.GetBehaviours<BreathBehaviour>();
        for (int i = 0; i < breathBehaviours.Length; i++)
            breathBehaviours[i].fastBreath = true;
    }
}
```

## GetBehaviours(int, int)

Returns all [StateMachineBehaviour](/engine/6000.6/script-reference/unityengine/statemachinebehaviour.md) that match type `T` or are derived from `T`. Returns null if none are found.

```csharp
public StateMachineBehaviour[] GetBehaviours(int fullPathHash, int layerIndex)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): **** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)):&#x20;

### Returns

| Type                                                                                              | Description |
| ------------------------------------------------------------------------------------------------- | ----------- |
| [StateMachineBehaviour\[\]](/engine/6000.6/script-reference/unityengine/statemachinebehaviour.md) |             |

### Examples

```csharp
using UnityEngine;
using System.Collections;

// An example StateMachineBehaviour.
public class BreathBehaviour : StateMachineBehaviour
{
    public bool  fastBreath;

    // OnStateUpdate is called at each Update frame between OnStateEnter and OnStateExit callback
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        animator.SetBool("FastBreath", fastBreath);
    }
}


public class RunBehaviour : StateMachineBehaviour
{
    // OnStateUpdate is called at each Update frame between OnStateEnter and OnStateExit callback
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        BreathBehaviour[] breathBehaviours = animator.GetBehaviours<BreathBehaviour>();
        for (int i = 0; i < breathBehaviours.Length; i++)
            breathBehaviours[i].fastBreath = true;
    }
}
```
