Spawner

Most games need some sort of object spawner. The internal spawn logic can look a bit different depending on scenario and context. This is why we created a scalable and modular Object Spawner.

Underlying all spawners is the ASpawner script. This is an extendable class that handles all the boring setup logic for a spawner. But, because of this, the direct inheritance could be abit difficult to grasp. Therefor, we created some sub-spawner systems to allow you to get the ball rolling faster.

To understand how we can create a new spawner to spawn a specific type, we can extend the SpawnpointsSpawner and create a script that spawns Balls.

// we extend SpawnpointsSpawner which requires two "arguments":
//    1: type to spawn (Ball)    2: the current type (BallSpawner)
public class BallSpawner : SpawnpointsSpawner<Ball, BallSpawner>
{
    public override Ball Spawn(Object obj, Vector3 point)
    {
        return Instantiate(obj.obj, point, Quaternion.identity); // instantiate the object.
    }
    
    public override void Dispose(Ball copy)
    {
        base.Dispose(copy); // must call.
        Destroy(copy.gameObject); // destroy the game object.
    }
}

Spawn object

To spawn an object from another script we simply need to call:

List of all pre-made spawners

SpawnpointsSpawner - spawns an object randomly between different spawnpoints. Spawnpoints are given as children of the spawner itself so it's easy to configure and visually see spawnpoints.
SinglePointSpawner - spawns an object randomly between different spawnpoints, but only 1 object can spawn per spawnpoint until that object gets disposed. Spawnpoints are given as children of the spawner itself so it's easy to configure and visually see spawnpoints.
InAreaSpawner - spawns an object in some pre-defined area. Area is defined by a Collider's (on the same object as the spawner) bounds.
InAreaSeparatedSpawner - spawns an object in some pre-defined area. Area is defined by a Collider's (on the same object as the spawner) bounds. Unlike InAreaSpawner, InAreaSeparatedSpawner allows a minimum distance between two objects.
LoopableSpawner - spawns an object in some pre-defined area. Area is defined by a Collider's (on the same object as the spawner) bounds. Spawning is loopable, meaning that it will constantly spawn new objects defined by inspector property delay.

Create custom spawner

Sometimes, the pre-made spawners are not enough and you would like to create your own spawning logic. Here's how:

Last updated