> For the complete documentation index, see [llms.txt](https://gley.gitbook.io/mobile-pedestrian-system/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gley.gitbook.io/mobile-pedestrian-system/events/onbehaviourchanged.md).

# OnBehaviourChanged

### Description

Triggered every time a pedestrian behaviour changes.

### Delegate

```csharp
public delegate void BehaviourChanged(int pedestrianIndex, PedestrianBehaviour newBehaviour);
```

### Parameters

| Name                | Description                  |
| ------------------- | ---------------------------- |
| **pedestrianIndex** | The index of the pedestrian. |
| **newBehaviour**    | The new active behaviour.    |

### Example

```csharp
using Gley.PedestrianSystem;
using UnityEngine;


public class Test : MonoBehaviour
{
    // A reference to the pedestrian pool and player assigned in the inspector.
    public PedestrianPool PedestrianPool;
    public Transform Player;

    void Start()
    {
        Events.OnBehaviourChanged += BehaviourChanged;
        API.Initialize(Player, 1, PedestrianPool);
    }

    private void BehaviourChanged(int pedestrianIndex, PedestrianBehaviour newBehaviour)
    {
        Debug.Log($"Pedestrian with index {pedestrianIndex} just changed the behaviour to {newBehaviour.Name}");
    }

    private void OnDestroy()
    {
        Events.OnBehaviourChanged -= BehaviourChanged;
    }
}
```
