> 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/complete-api/setpath.md).

# SetPath

### Description

A specific predefined path can be assigned to any active pedestrian within the Pedestrian System.

The path consists of a list of waypoint indexes, and the pedestrian will follow these waypoints instead of requesting random ones.

If a pedestrian has a predefined path, it will not be removed by the pooling system.

### Declaration

```csharp
 public static void SetPath(int pedestrianIndex, List<int> path)
```

### Parameters

<table><thead><tr><th width="261">Name</th><th>Description</th></tr></thead><tbody><tr><td><strong>pedestrianIndex</strong></td><td>The index of the pedestrian.</td></tr><tr><td><strong>path</strong></td><td>A list of path waypoint indexes.</td></tr></tbody></table>

### Example

```csharp
using Gley.PedestrianSystem;
using System.Collections.Generic;
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 AddPathToPedestrian()
    {
        // Get the path from start to end.
        Vector3 startPosition = new Vector3(0, 0, 0);
        Vector3 endPosition = new Vector3(0, 0, 350);
        List<int> path = API.GetPath(startPosition, endPosition, PedestrianTypes.Normal);

        if (path.Count > 0)
        {
            // Assign the path to the pedestrian with index 0.
            API.SetPath(0, path);
        }
        else
        {
            Debug.Log("No path found");
        }
    }

    private void DestinationReached(int pedestrianIndex)
    {
        // When pedestrian 0 reaches the destination, remove the path and continue as a normal pedestrian.
        if (pedestrianIndex == 0)
        {
            API.RemovePath(0);
        }
    }

    private void OnDestroy()
    {
        //don't forget to remove the events
        PedestrianEvents.onDestinationReached -= DestinationReached;
    }

    // For demonstration purposes.
    private void Update()
    {
        if(Input.GetKeyDown(KeyCode.Space))
        {
            AddPathToPedestrian();
        }
    }
}

```
