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

# OnWaypointReached

### Description

Triggered every time a waypoint that has the Trigger Event option enabled is reached by a pedestrian.

### Delegate

```csharp
 public delegate void WaypointReached(int pedestrianIndex, int waypointIndex, string data);
```

### Parameters

| Name                | Description                                            |
| ------------------- | ------------------------------------------------------ |
| **pedestrianIndex** | The index of the pedestrian that reached the waypoint. |
| **waypointIndex**   | The waypoint index that triggered the event.           |
| **data**            | The data set on that waypoint by Trigger Event option. |

### 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, 20, PedestrianPool);
        Events.OnWaypointReached += WaypointReached;
    }

    /// <summary>
    /// Triggered every time a waypoint with Trigger Event box checked is reached
    /// </summary>
    /// <param name="pedestrianIndex">the pedestrian index that reached the waypoint</param>
    /// <param name="waypointIndex">the index of the waypoint</param>
    /// <param name="data">the data from the settings window</param>
    private void WaypointReached(int pedestrianIndex, int waypointIndex, string data)
    {
        Debug.Log(pedestrianIndex + " " + waypointIndex + " " + data);

    }

    private void OnDestroy()
    {
        Events.OnWaypointReached -= WaypointReached;
    }
}
```
