# Spawn Point Manager

Each [**Projectile Spawner**](/magic-pig-games/projectile-factory/projectile-factory-documentation/projectile-spawner.md) 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="/files/iUx6P3lPvT4Kb6NoBzGc" 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://infinitypbr.gitbook.io/magic-pig-games/projectile-factory/projectile-factory-documentation/spawn-point-manager.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
