> For the complete documentation index, see [llms.txt](https://gley.gitbook.io/mobile-traffic-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-traffic-system/events/onwaypointreached.md).

# onWaypointReached

## Description

Triggered every time a waypoint that has the[ Trigger Event](/mobile-traffic-system/setup-guide/waypoint-properties.md#trigger-events)[ ](/mobile-traffic-system/setup-guide.md)option enabled is reached by a vehicle.

<table><thead><tr><th width="220">Name</th><th>Description</th></tr></thead><tbody><tr><td><strong>vehicleIndex</strong></td><td>The index of the vehicle that reached the waypoint.</td></tr><tr><td><strong>waypointIndex</strong></td><td>The waypoint index that triggered the event.</td></tr><tr><td><strong>data</strong></td><td>The data set on that waypoint by Trigger Event option.</td></tr></tbody></table>

## Example

```csharp
using Gley.TrafficSystem;
using UnityEngine;
public class Test : MonoBehaviour
{
    //a reference to vehicle pool and player assigned in inspector
    public VehiclePool vehiclePool;
    public Transform player;

    void Start()
    {
        API.Initialize(player, 20, vehiclePool);
        Events.onWaypointReached += WaypointReached;
    }

    /// <summary>
    /// Triggered every time a waypoint with Trigger Event check mark on is reached
    /// </summary>
    /// <param name="vehicleIndex">the vehicle 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 vehicleIndex, int waypointIndex, string data)
    {
        Debug.Log(vehicleIndex + " " + waypointIndex + " " + data);
    }

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

```
