> 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/ondestinationchanged.md).

# OnDestinationChanged

### Description

Triggered every time a pedestrian changes a waypoint.

### Delegate

```csharp
public delegate void DestinationChanged(int pedestrianIndex, Vector3 newDestination);
```

### Parameters

| Name                | Description                             |
| ------------------- | --------------------------------------- |
| **pedestrianIndex** | The index of the pedestrian.            |
| **newDestination**  | The new destination for the pedestrian. |

### 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.OnDestinationChanged += DestinationChanged;
        API.Initialize(Player, 1, PedestrianPool);
    }

    private void DestinationChanged(int pedestrianIndex, Vector3 newDestination)
    {
        Debug.Log($"Pedestrian with index {pedestrianIndex} changed destination to {newDestination}");
    }

    private void OnDestroy()
    {
        Events.OnDestinationChanged -= DestinationChanged;
    }
}
```
