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:
public BallSpawner spawner; // reference to your desired spawner.
Ball ball = spawner.Spawn(); // spawn.
spawner.Dispose(ball); // to destroy object.
spawner.RemoveAll(); // to remove all objects that has spawned.
List of all pre-made spawners
Create custom spawner
Sometimes, the pre-made spawners are not enough and you would like to create your own spawning logic. Here's how:
// we extend ASpawner which requires two "arguments":
// 1: type to spawn (Ball) 2: the current type (BallSpawner)
public class BallSpawner : ASpawner<Ball, BallSpawner>
{
// must be overriden.
public override Ball Spawn(Object obj, Vector3 point)
{
return // instantiate logic goes here
}
// must be overriden
protected override Vector3 GetNewPoint()
{
return // custom location logic here
}
// can be overriden
protected override void Dispose()
{
base.Dispose();
// dispose for EVERYTHING logic here
}
// can be overriden
public override void Dispose(Ball copy)
{
base.Dispose(copy);
// dispose for specific object logic here
}
}
Last updated