Skip to content

Spawner

namespace Griff.Scenes;
public sealed class Spawner : Component

Spawns copies of a prefab every Interval seconds at its position, with no code: enemy waves, falling rocks, collectibles that come back. Limit it with Count and MaxAlive. With Beats set, it spawns on the beat of a BeatClock instead.

This is a component: its saved properties are on its component page.

public IReadOnlyList<Entity> Alive { get; }

Its spawns still in the scene.

public int BeatOffset { get; set; }

Steps this many beats later: with two spawners on every 2 beats, one 1 beat later, they take turns.

public int Beats { get; set; }

Steps to the music of a BeatClock: spawns on every this many beats instead of every Interval seconds, once Delay has passed. A spawn that has no room waits for the next. 0 goes by seconds.

public string? Clock { get; set; }

The entity whose BeatClock it steps to. Empty follows the first in the scene.

public int Count { get; set; }

How many to spawn in all; 0 keeps going forever.

public float Delay { get; set; }

Seconds before the first spawn.

public float Interval { get; set; }

Seconds between spawns (unless it steps to the Beats).

public bool IsFinished { get; }

True once it has spawned Count.

public int MaxAlive { get; set; }

How many of its spawns may be around at once; 0 is no limit. When one is destroyed it makes room, and the next spawns as soon as it’s due.

public string? NeedsFlag { get; set; }

A flag that has to be set before it starts spawning, e.g. “AlarmRaised” (set by a trigger’s Set Flag, a dialogue’s “[set AlarmRaised]” or a script’s Game.SetFlag), or “not AlarmRaised” to spawn only while it isn’t. Its count down waits until then; its Spawn action still spawns one.

public string? Prefab { get; set; }

The prefab to spawn, e.g. “Enemy” (Assets/Prefabs/Enemy.prefab).

public float Radius { get; set; }

Spawns land at a random spot up to this far from the spawner.

public bool Running { get; set; }

Untick it to stop spawning for now. Switches tick and untick it.

public int Spawned { get; }

How many it has spawned.

public event Action<Entity>? EntitySpawned

Raised with each new spawn, e.g. to give it a speed or a target.