# Spawn Point Manager

Each [**Projectile Spawner**](https://infinitypbr.gitbook.io/magic-pig-games/projectile-factory/projectile-factory-documentation/projectile-spawner) can have any number of *Spawn Points*. These are the points where Projectiles will be created.

The `SpawnPointManager` is a class which handles how each Spawn Point is used.&#x20;

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FjZ5wmGHmD540LqvJCJfw%2FScreenshot%202024-04-01%20at%208.20.30%E2%80%AFPM.png?alt=media&#x26;token=b78c3ef3-6450-4ea2-89eb-8f2aecc3cc7d" alt=""><figcaption><p>Here we have two spawn points, and one Manager.</p></figcaption></figure>

The default `SpawnPointManager` simply moves from one Spawn Point to the next sequentially, as shown in the code below. You can create a new class which inherits from this in order to customize how your Spawn Points are selected.

```csharp
namespace MagicPigGames.Projectiles
{
    [CreateAssetMenu(fileName = "New Sequential Spawn Points", menuName = "Projectile System/Spawn Point Managers/Sequential Spawn Points")]
    [System.Serializable]
    public class SpawnPointManager : ScriptableObject
    {
        public virtual int NextSpawnPointIndex(ProjectileSpawner projectileSpawner, int value = 1)
        {
            if (projectileSpawner.spawnPoints.Count == 0)
                throw new InvalidOperationException("There are no spawn points available.");

            projectileSpawner.SpawnPointIndex += value;
            
            if (projectileSpawner.SpawnPointIndex < 0)
                projectileSpawner.SpawnPointIndex += projectileSpawner.spawnPoints.Count;
            projectileSpawner.SpawnPointIndex %= projectileSpawner.spawnPoints.Count;

            return projectileSpawner.SpawnPointIndex;
        }
    }
}
```

**Your game is unique!** And your Spawners are unique as well! Customizing how the Spawn Points are selected is a powerful tool.

## Customization Scenario

As an example, perhaps your spawner has multiple spawn positions, and they sequentially fire as in the default `SpawnPointManager` -- except that each one can be destroyed by the player. As the player destroys them, you may wish to skip over the ones that have been destroyed.
