Central coordinator for runtime spawning. Supports three spawn flows:
-
Global spawning – distributed across the world with population caps.
-
Region spawning – localized spawners that activate when the player enters a region.
-
Wave spawning – table-driven encounter waves triggered by WaveTrigger volumes.
Also provides optional internal culling beyond a configurable distance and integrates with an object pool.
More...
|
void | SetConcurrentAliveCap (int cap) |
| Sets the upper limit for concurrently alive spawned objects (global/region/wave combined).
|
|
void | SetGlobalSpawnWindow (int min, int max) |
| Sets the target global spawn window. The global loop tries to keep population within these bounds.
|
|
void | SetSpawnRateMultiplier (float mult) |
| Applies a multiplier to the global spawn tick rate. Values < 1 slow down, > 1 speed up.
|
|
void | SetWaveRateMultiplier (float mult) |
| Applies a multiplier to the wave interval timing. Values < 1 shorten intervals, > 1 lengthen them.
|
|
void | Init () |
| Discovers child regions, wires services, synchronizes events, and initializes collaborators. Safe to call multiple times; subsequent calls re-scan regions and clear internal caches.
|
|
void | StartSpawners () |
| Creates object pools and starts the enabled spawn loops (global, region, wave collaborators). Calls Init if not already initialized.
|
|
void | SetPlayer (GameObject player) |
| Assigns the player object used for distance checks and context building.
|
|
void | SetStartAutomatically (bool value) |
| Sets whether the spawner should automatically initialize and start on Start.
|
|
void | ActivateWaveTrigger (WaveTrigger trigger) |
| Programmatically activates a wave trigger using the same internal flow as volume activation.
|
|
void | DeactivateWaveTrigger (WaveTrigger trigger) |
| Stops a running wave sequence and marks the trigger as inactive.
|
|
void | NotifyWaveTriggerActivated (WaveTrigger trigger) |
| Notifies listeners that a wave trigger has been activated. Safe instance-side way to forward triggers without touching static events.
|
|
void | AddRegion () |
| Creates a new child LocalAreaSpawner with a default BoxCollider trigger.
|
|
void | ShowHideSpawnVolumes () |
| Toggles visibility of region spawn volumes in Scene View.
|
|
void | ShowHideWaveTriggers () |
| Toggles visibility of wave triggers in Scene View.
|
|
WaveTrigger | AddWaveTrigger () |
| Creates and adds a new WaveTrigger child with a default BoxCollider trigger.
|
|
void | ShowOccluderRange () |
| Toggles drawing of the culling radius gizmo around the player.
|
|
void | DrawWorldExtents () |
| Toggles drawing of world extents gizmo.
|
|
|
static void | Despawn (GameObject go) |
| Convenience API to despawn a spawned object when the owner spawner is unknown. Attempts to resolve the owner spawner; falls back to any spawner in scene or destroys the object.
|
|
static WaveSpawner | CreateWaveSpawner (string path) |
| Creates a WaveSpawner asset at the given project path.
|
|
static SpawnEntry | CreateSpawnEntry (string path) |
| Creates a SpawnEntry asset at the given project path.
|
|
|
bool | UseInternalCulling [get, set] |
| Enables the built-in culling loop that despawns objects farther than cullDistance from the player.
|
|
bool | UseGlobalSpawners [get, set] |
| Enables global spawners (non-localized spawns that obey global population caps).
|
|
bool | UseRegionSpawners [get, set] |
| Enables region spawners (localized spawns activated by player presence in LocalAreaSpawners).
|
|
bool | UseWaveSpawners [get, set] |
| Enables wave spawners (scriptable wave tables triggered via WaveTrigger).
|
|
string | PlayerTag [get, set] |
| Tag used to locate the player (if playerObject is not assigned).
|
|
List< GameObject > | SpawnedObjects [get] |
| Live list of spawned objects. Kept in sync by PopulationTracker.
|
|
List< SpawnEntry > | GlobalSpawners [get, set] |
| Global spawn entries used by the global spawn loop.
|
|
List< string > | NavmeshAreas [get, set] |
| Optional list of NavMesh area names to constrain spawn placement.
|
|
List< LocalAreaSpawner > | SpawnRegions [get, set] |
| All configured spawn regions (children discovered on Init).
|
|
List< WaveTrigger > | WaveTriggers [get, set] |
| Configured wave triggers for table-driven encounters.
|
|
float | CullDistance [get] |
| Culling radius in world units.
|
|
Vector2 | WorldSizeVector2 [get] |
| World extents (X,Z) for global spawning and gizmos.
|
|
float | MinSpawnRange [get] |
| Minimum allowed distance from player for spawn placement.
|
|
int | MinGlobalObjectCount [get, set] |
| Minimum desired global population (the global loop tries to maintain between min/max).
|
|
int | MaxGlobalObjectCount [get, set] |
| Maximum desired global population (the global loop tries to maintain between min/max).
|
|
Transform | PlayerTransform [get] |
| Player transform for range checks and spawn context; returns null if unknown.
|
|
Vector3 | WorldSizeVector3 [get] |
| World extents as a 3D vector (Y fixed to 5 for visualization).
|
|
bool | LogSpawnEntries [get] |
| Enables logging of key spawn events to the Console.
|
|
bool | DrawExtents [get] |
| When true, draws world extents in Scene View.
|
|
bool | IsInitialized [get] |
| property so other services can check if the spawner is active and ready
|
|
PopulationTracker | Population [get] |
| Exposes the population tracker.
|
|
ISpawnExecutor | Executor [get] |
| Exposes the spawn executor used by all loops.
|
|
ISpawnLocator | Locator [get] |
| Exposes the spawn locator used for placement queries.
|
|
|
static readonly Dictionary< GameObject, RuntimeSpawner > | s_OwnerByGO = new() |
| Static registry mapping spawned instances back to their owning RuntimeSpawner. Used to route Despawn(GameObject) when the owner isn't directly known.
|
|
Central coordinator for runtime spawning. Supports three spawn flows:
-
Global spawning – distributed across the world with population caps.
-
Region spawning – localized spawners that activate when the player enters a region.
-
Wave spawning – table-driven encounter waves triggered by WaveTrigger volumes.
Also provides optional internal culling beyond a configurable distance and integrates with an object pool.
◆ ActivateWaveTrigger()
void MegaCrush.Spawner.RuntimeSpawner.ActivateWaveTrigger |
( |
WaveTrigger | trigger | ) |
|
Programmatically activates a wave trigger using the same internal flow as volume activation.
◆ AddRegion()
void MegaCrush.Spawner.RuntimeSpawner.AddRegion |
( |
| ) |
|
Creates a new child LocalAreaSpawner with a default BoxCollider trigger.
◆ AddWaveTrigger()
WaveTrigger MegaCrush.Spawner.RuntimeSpawner.AddWaveTrigger |
( |
| ) |
|
Creates and adds a new WaveTrigger child with a default BoxCollider trigger.
◆ Awake()
void MegaCrush.Spawner.RuntimeSpawner.Awake |
( |
| ) |
|
|
private |
◆ CreateObjectPools()
void MegaCrush.Spawner.RuntimeSpawner.CreateObjectPools |
( |
| ) |
|
|
private |
Ensures object pools exist for all configured global, region, and wave entries.
◆ CreateSpawnEntry()
static SpawnEntry MegaCrush.Spawner.RuntimeSpawner.CreateSpawnEntry |
( |
string | path | ) |
|
|
static |
Creates a SpawnEntry asset at the given project path.
◆ CreateWaveSpawner()
static WaveSpawner MegaCrush.Spawner.RuntimeSpawner.CreateWaveSpawner |
( |
string | path | ) |
|
|
static |
Creates a WaveSpawner asset at the given project path.
◆ DeactivateWaveTrigger()
void MegaCrush.Spawner.RuntimeSpawner.DeactivateWaveTrigger |
( |
WaveTrigger | trigger | ) |
|
Stops a running wave sequence and marks the trigger as inactive.
◆ DeferWaveUntilInitialized()
IEnumerator MegaCrush.Spawner.RuntimeSpawner.DeferWaveUntilInitialized |
( |
WaveTrigger | trigger | ) |
|
|
private |
◆ Despawn()
static void MegaCrush.Spawner.RuntimeSpawner.Despawn |
( |
GameObject | go | ) |
|
|
static |
Convenience API to despawn a spawned object when the owner spawner is unknown. Attempts to resolve the owner spawner; falls back to any spawner in scene or destroys the object.
- Parameters
-
go | Spawned object to despawn. |
◆ DespawnInternal()
void MegaCrush.Spawner.RuntimeSpawner.DespawnInternal |
( |
GameObject | go | ) |
|
|
private |
Returns an instance to the pool, updates population and events, and clears ownership bookkeeping.
- Parameters
-
◆ DoCulling()
IEnumerator MegaCrush.Spawner.RuntimeSpawner.DoCulling |
( |
| ) |
|
|
private |
Periodically checks spawned objects and despawns them if they exceed CullDistance.
◆ DrawWorldExtents()
void MegaCrush.Spawner.RuntimeSpawner.DrawWorldExtents |
( |
| ) |
|
Toggles drawing of world extents gizmo.
◆ GetSettings()
Loads or creates the editor settings asset for gizmo colors and other preferences.
◆ Init()
void MegaCrush.Spawner.RuntimeSpawner.Init |
( |
| ) |
|
Discovers child regions, wires services, synchronizes events, and initializes collaborators. Safe to call multiple times; subsequent calls re-scan regions and clear internal caches.
◆ NotifyWaveTriggerActivated()
void MegaCrush.Spawner.RuntimeSpawner.NotifyWaveTriggerActivated |
( |
WaveTrigger | trigger | ) |
|
Notifies listeners that a wave trigger has been activated. Safe instance-side way to forward triggers without touching static events.
◆ OnDisable()
void MegaCrush.Spawner.RuntimeSpawner.OnDisable |
( |
| ) |
|
|
private |
◆ OnDrawGizmosSelected()
void MegaCrush.Spawner.RuntimeSpawner.OnDrawGizmosSelected |
( |
| ) |
|
|
private |
◆ OnObjectCulled()
void MegaCrush.Spawner.RuntimeSpawner.OnObjectCulled |
( |
GameObject | thisObject | ) |
|
|
private |
Callback hook for culling; returns the object to pool and updates bookkeeping.
◆ OnPlayerEnteredRegion()
void MegaCrush.Spawner.RuntimeSpawner.OnPlayerEnteredRegion |
( |
LocalAreaSpawner | region, |
|
|
bool | isInRegion ) |
|
private |
Maintains the active region set based on player presence notifications from LocalAreaSpawner.
◆ OnUnitDied()
void MegaCrush.Spawner.RuntimeSpawner.OnUnitDied |
( |
GameObject | thisObject | ) |
|
|
private |
Callback hook for unit death; returns the object to pool and updates bookkeeping.
◆ OnWaveTriggerActivated()
void MegaCrush.Spawner.RuntimeSpawner.OnWaveTriggerActivated |
( |
WaveTrigger | thisTrigger | ) |
|
|
private |
Handles activation of wave triggers and starts their wave sequence coroutine.
◆ RunWaveSequence()
IEnumerator MegaCrush.Spawner.RuntimeSpawner.RunWaveSequence |
( |
WaveTrigger | trigger | ) |
|
|
private |
Runs the configured waves for a trigger once (per-wave looping policy honored inside the runner).
◆ SetConcurrentAliveCap()
void MegaCrush.Spawner.RuntimeSpawner.SetConcurrentAliveCap |
( |
int | cap | ) |
|
Sets the upper limit for concurrently alive spawned objects (global/region/wave combined).
- Parameters
-
cap | New concurrent alive cap (min 1). |
◆ SetGlobalSpawnWindow()
void MegaCrush.Spawner.RuntimeSpawner.SetGlobalSpawnWindow |
( |
int | min, |
|
|
int | max ) |
Sets the target global spawn window. The global loop tries to keep population within these bounds.
- Parameters
-
min | Minimum desired population (clamped to ≥ 0). |
max | Maximum desired population (clamped to ≥ min ). |
◆ SetPlayer()
void MegaCrush.Spawner.RuntimeSpawner.SetPlayer |
( |
GameObject | player | ) |
|
Assigns the player object used for distance checks and context building.
◆ SetSpawnRateMultiplier()
void MegaCrush.Spawner.RuntimeSpawner.SetSpawnRateMultiplier |
( |
float | mult | ) |
|
Applies a multiplier to the global spawn tick rate. Values < 1 slow down, > 1 speed up.
- Parameters
-
mult | Rate multiplier (min 0.01). |
◆ SetStartAutomatically()
void MegaCrush.Spawner.RuntimeSpawner.SetStartAutomatically |
( |
bool | value | ) |
|
Sets whether the spawner should automatically initialize and start on Start.
◆ SetWaveRateMultiplier()
void MegaCrush.Spawner.RuntimeSpawner.SetWaveRateMultiplier |
( |
float | mult | ) |
|
Applies a multiplier to the wave interval timing. Values < 1 shorten intervals, > 1 lengthen them.
- Parameters
-
mult | Wave timing multiplier (min 0.01). |
◆ ShowHideSpawnVolumes()
void MegaCrush.Spawner.RuntimeSpawner.ShowHideSpawnVolumes |
( |
| ) |
|
Toggles visibility of region spawn volumes in Scene View.
◆ ShowHideWaveTriggers()
void MegaCrush.Spawner.RuntimeSpawner.ShowHideWaveTriggers |
( |
| ) |
|
Toggles visibility of wave triggers in Scene View.
◆ ShowOccluderRange()
void MegaCrush.Spawner.RuntimeSpawner.ShowOccluderRange |
( |
| ) |
|
Toggles drawing of the culling radius gizmo around the player.
◆ Start()
void MegaCrush.Spawner.RuntimeSpawner.Start |
( |
| ) |
|
|
private |
◆ StartSpawners()
void MegaCrush.Spawner.RuntimeSpawner.StartSpawners |
( |
| ) |
|
Creates object pools and starts the enabled spawn loops (global, region, wave collaborators). Calls Init if not already initialized.
◆ _executor
◆ _globalCoro
Coroutine MegaCrush.Spawner.RuntimeSpawner._globalCoro |
|
private |
◆ _globalLoop
◆ _locator
◆ _pool
◆ _pop
◆ _regionCoro
Coroutine MegaCrush.Spawner.RuntimeSpawner._regionCoro |
|
private |
◆ _regionLoop
◆ _spawnRateMult
float MegaCrush.Spawner.RuntimeSpawner._spawnRateMult = 1f |
|
private |
◆ _waveCoros
readonly Dictionary<WaveTrigger, Coroutine> MegaCrush.Spawner.RuntimeSpawner._waveCoros = new() |
|
private |
◆ _waveExec
◆ _waveRateMult
float MegaCrush.Spawner.RuntimeSpawner._waveRateMult = 1f |
|
private |
◆ activeSpawnRegions
List<LocalAreaSpawner> MegaCrush.Spawner.RuntimeSpawner.activeSpawnRegions = new() |
|
private |
◆ autoLaunchOnStart
bool MegaCrush.Spawner.RuntimeSpawner.autoLaunchOnStart = false |
|
private |
◆ cullDistance
float MegaCrush.Spawner.RuntimeSpawner.cullDistance = 100 |
|
private |
◆ cullingCheckFrequency
int MegaCrush.Spawner.RuntimeSpawner.cullingCheckFrequency = 2 |
|
private |
◆ drawExtents
bool MegaCrush.Spawner.RuntimeSpawner.drawExtents = false |
|
private |
◆ globalSpawners
List<SpawnEntry> MegaCrush.Spawner.RuntimeSpawner.globalSpawners = new() |
|
private |
◆ initialized
bool MegaCrush.Spawner.RuntimeSpawner.initialized = false |
|
private |
◆ layerMask
LayerMask MegaCrush.Spawner.RuntimeSpawner.layerMask |
|
private |
◆ logSpawnEntries
bool MegaCrush.Spawner.RuntimeSpawner.logSpawnEntries = false |
|
private |
◆ maxGlobalObjectCount
int MegaCrush.Spawner.RuntimeSpawner.maxGlobalObjectCount = 25 |
|
private |
◆ maxObjectCount
int MegaCrush.Spawner.RuntimeSpawner.maxObjectCount = 100 |
|
private |
◆ minGlobalObjectCount
int MegaCrush.Spawner.RuntimeSpawner.minGlobalObjectCount = 25 |
|
private |
◆ minSpawnRange
float MegaCrush.Spawner.RuntimeSpawner.minSpawnRange = 25 |
|
private |
◆ newGlobalSpawners
readonly List<GameObject> MegaCrush.Spawner.RuntimeSpawner.newGlobalSpawners = new() |
|
private |
◆ newRegionSpawners
readonly List<GameObject> MegaCrush.Spawner.RuntimeSpawner.newRegionSpawners = new() |
|
private |
◆ newWaveSpawners
readonly List<GameObject> MegaCrush.Spawner.RuntimeSpawner.newWaveSpawners = new() |
|
private |
◆ playerObject
GameObject MegaCrush.Spawner.RuntimeSpawner.playerObject |
|
private |
◆ playerTag
string MegaCrush.Spawner.RuntimeSpawner.playerTag = "Player" |
|
private |
◆ restrictToNavmeshAreas
List<string> MegaCrush.Spawner.RuntimeSpawner.restrictToNavmeshAreas = new() |
|
private |
◆ s_OwnerByGO
readonly Dictionary<GameObject, RuntimeSpawner> MegaCrush.Spawner.RuntimeSpawner.s_OwnerByGO = new() |
|
staticprivate |
Static registry mapping spawned instances back to their owning RuntimeSpawner. Used to route Despawn(GameObject) when the owner isn't directly known.
◆ settings
◆ showOccluderRange
bool MegaCrush.Spawner.RuntimeSpawner.showOccluderRange = false |
|
private |
◆ showSpawnTriggers
bool MegaCrush.Spawner.RuntimeSpawner.showSpawnTriggers = false |
|
private |
◆ showSpawnVolumes
bool MegaCrush.Spawner.RuntimeSpawner.showSpawnVolumes = true |
|
private |
◆ spawnedObjects
List<GameObject> MegaCrush.Spawner.RuntimeSpawner.spawnedObjects = new() |
|
private |
Retained for Inspector display; kept in sync by PopulationTracker.
◆ spawnerTag
string MegaCrush.Spawner.RuntimeSpawner.spawnerTag = string.Empty |
|
private |
◆ spawnRegions
◆ useGlobalSpawners
bool MegaCrush.Spawner.RuntimeSpawner.useGlobalSpawners = false |
|
private |
◆ useInternalCulling
bool MegaCrush.Spawner.RuntimeSpawner.useInternalCulling = true |
|
private |
◆ useRegionSpawners
bool MegaCrush.Spawner.RuntimeSpawner.useRegionSpawners = false |
|
private |
◆ useWaveSpawners
bool MegaCrush.Spawner.RuntimeSpawner.useWaveSpawners = false |
|
private |
◆ waveTriggers
List<WaveTrigger> MegaCrush.Spawner.RuntimeSpawner.waveTriggers = new() |
|
private |
◆ worldSize
Vector2 MegaCrush.Spawner.RuntimeSpawner.worldSize = new(50, 50) |
|
private |
◆ CullDistance
float MegaCrush.Spawner.RuntimeSpawner.CullDistance |
|
get |
Culling radius in world units.
◆ DrawExtents
bool MegaCrush.Spawner.RuntimeSpawner.DrawExtents |
|
get |
When true, draws world extents in Scene View.
◆ Executor
Exposes the spawn executor used by all loops.
◆ GlobalSpawners
List<SpawnEntry> MegaCrush.Spawner.RuntimeSpawner.GlobalSpawners |
|
getset |
Global spawn entries used by the global spawn loop.
◆ IsInitialized
bool MegaCrush.Spawner.RuntimeSpawner.IsInitialized |
|
get |
property so other services can check if the spawner is active and ready
◆ Locator
Exposes the spawn locator used for placement queries.
◆ LogSpawnEntries
bool MegaCrush.Spawner.RuntimeSpawner.LogSpawnEntries |
|
get |
Enables logging of key spawn events to the Console.
◆ MaxGlobalObjectCount
int MegaCrush.Spawner.RuntimeSpawner.MaxGlobalObjectCount |
|
getset |
Maximum desired global population (the global loop tries to maintain between min/max).
◆ MinGlobalObjectCount
int MegaCrush.Spawner.RuntimeSpawner.MinGlobalObjectCount |
|
getset |
Minimum desired global population (the global loop tries to maintain between min/max).
◆ MinSpawnRange
float MegaCrush.Spawner.RuntimeSpawner.MinSpawnRange |
|
get |
Minimum allowed distance from player for spawn placement.
◆ NavmeshAreas
List<string> MegaCrush.Spawner.RuntimeSpawner.NavmeshAreas |
|
getset |
Optional list of NavMesh area names to constrain spawn placement.
◆ PlayerTag
string MegaCrush.Spawner.RuntimeSpawner.PlayerTag |
|
getset |
Tag used to locate the player (if playerObject is not assigned).
◆ PlayerTransform
Transform MegaCrush.Spawner.RuntimeSpawner.PlayerTransform |
|
get |
Player transform for range checks and spawn context; returns null
if unknown.
◆ Population
Exposes the population tracker.
◆ SpawnedObjects
List<GameObject> MegaCrush.Spawner.RuntimeSpawner.SpawnedObjects |
|
get |
Live list of spawned objects. Kept in sync by PopulationTracker.
◆ SpawnRegions
All configured spawn regions (children discovered on Init).
◆ UseGlobalSpawners
bool MegaCrush.Spawner.RuntimeSpawner.UseGlobalSpawners |
|
getset |
Enables global spawners (non-localized spawns that obey global population caps).
◆ UseInternalCulling
bool MegaCrush.Spawner.RuntimeSpawner.UseInternalCulling |
|
getset |
Enables the built-in culling loop that despawns objects farther than cullDistance from the player.
◆ UseRegionSpawners
bool MegaCrush.Spawner.RuntimeSpawner.UseRegionSpawners |
|
getset |
Enables region spawners (localized spawns activated by player presence in LocalAreaSpawners).
◆ UseWaveSpawners
bool MegaCrush.Spawner.RuntimeSpawner.UseWaveSpawners |
|
getset |
Enables wave spawners (scriptable wave tables triggered via WaveTrigger).
◆ WaveTriggers
List<WaveTrigger> MegaCrush.Spawner.RuntimeSpawner.WaveTriggers |
|
getset |
Configured wave triggers for table-driven encounters.
◆ WorldSizeVector2
Vector2 MegaCrush.Spawner.RuntimeSpawner.WorldSizeVector2 |
|
get |
World extents (X,Z) for global spawning and gizmos.
◆ WorldSizeVector3
Vector3 MegaCrush.Spawner.RuntimeSpawner.WorldSizeVector3 |
|
get |
World extents as a 3D vector (Y fixed to 5 for visualization).
◆ onNewWaveTriggered
Action<WaveEntry> MegaCrush.Spawner.RuntimeSpawner.onNewWaveTriggered |
|
static |
Raised when a wave entry is about to begin.
◆ onObjectCulled
Action<GameObject> MegaCrush.Spawner.RuntimeSpawner.onObjectCulled |
|
static |
Raised when an object is culled (internal or manual despawn).
◆ onObjectSpawned
Action<GameObject> MegaCrush.Spawner.RuntimeSpawner.onObjectSpawned |
|
static |
Raised when an object is spawned by any loop.
◆ onSpawnerInit
Action<float> MegaCrush.Spawner.RuntimeSpawner.onSpawnerInit |
|
static |
Raised after Init; supplies the configured cullDistance.
◆ onUpdateCurrentPopulation
Action<int> MegaCrush.Spawner.RuntimeSpawner.onUpdateCurrentPopulation |
|
static |
Raised when total spawned population changes.
◆ onWaveSpawnerComplete
Action<WaveTrigger> MegaCrush.Spawner.RuntimeSpawner.onWaveSpawnerComplete |
|
static |
Raised when a wave spawner completes its sequence.
◆ onWaveTriggerActivated
Action<WaveTrigger> MegaCrush.Spawner.RuntimeSpawner.onWaveTriggerActivated |
|
static |
Raised when a wave trigger volume becomes active.
The documentation for this class was generated from the following file:
- D:/projects/Asset Store Packages/com.pixelwizards.runtimespawner/Code/Runtime/Components/RuntimeSpawner.cs