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

# OnDestinationReached

### Description

Triggered every time a pedestrian that had a custom path reached its destination. (The last waypoint from the path).

### Delegate

```csharp
public delegate void DestinationReached(int pedestrianIndex);
```

### Parameters

| Name                | Description                  |
| ------------------- | ---------------------------- |
| **pedestrianIndex** | The index of 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()
    {
        API.Initialize(player, 1, pedestrianPool);
        PedestrianEvents.onDestinationReached += DestinationReached;
    }

    public void SetDestination()
    {
        // Set a random destination.
        Vector3 destination = new Vector3(Random.Range(-500, 500), 0, Random.Range(-500, 500));

        // Make the vehicle with index 0 drive to the destination.
        API.SetDestination(0, destination);
    }

    private void DestinationReached(int pedestrianIndex)
    {
        if (pedestrianIndex == 0)
        {
            // Set another random destination for this vehicle if the previous one was reached.
            Vector3 destination = new Vector3(Random.Range(-500, 500), 0, Random.Range(-500, 500));
            API.SetDestination(pedestrianIndex, destination);
        }
    }

    private void OnDestroy()
    {
        PedestrianEvents.onDestinationReached -= DestinationReached;
    }
}

```
