> 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/delegates/spawn-waypoint-selector.md).

# Spawn Waypoint Selector

### Description

Controls the selection of a free waypoint to instantiate a new pedestrian.

### Declaration

```csharp
public delegate int PedestrianSpawnWaypointSelector(List<Vector2Int> neighbors, Vector3 position, Vector3 direction, PedestrianTypes pedestrianType, bool useWaypointPriority);
```

### Parameters

<table><thead><tr><th width="211">Name</th><th>Description</th></tr></thead><tbody><tr><td>neighbors</td><td>A list of the cell indexes that are neighbors to the player cell.</td></tr><tr><td>position</td><td>The player position.</td></tr><tr><td>direction</td><td>The player direction.</td></tr><tr><td>pedestrianType</td><td>The pedestrian type for which the waypoint is being selected.</td></tr><tr><td>useWaypointPriority</td><td>Specifies whether waypoint priority is enabled for selection or not.</td></tr></tbody></table>

### Returns

**int** - a waypoint index

### Set Method

```csharp
public static void SetSpawnWaypointSelector(PedestrianSpawnWaypointSelector spawnWaypointSelectorDelegate)
```

### 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);
    }

    public void SetNewDelegate()
    {
        Delegates.SetSpawnWaypointSelector(MySpawnWaypointSelector);
    }

    public static int MySpawnWaypointSelector(List<Vector2Int> neighbors, Vector3 position, Vector3 direction, PedestrianTypes pedestrianType, bool useWaypointPriority)
    {
        //select a random cell
        Vector2Int selectedNeighbor = neighbors[Random.Range(0, neighbors.Count)];

        //return a random waypoint from that cell
        return GetPossibleWaypoint(selectedNeighbor, pedestrianType, useWaypointPriority);
    }


    // Used for demonstration purposes.
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            SetNewDelegate();
        }
    }
}
```

{% hint style="info" %}
Default delegate implementation can be found inside **DefaultPedestrianDelegates.cs**
{% endhint %}
