Wave Trigger
The Runtime Spawner includes a complete wave spawning system, similar to Tower Defense games, and many other ‘hold & defend’ games and missions (Left 4 Dead, etc). The Trigger area is defined by a Box Collider (set to ‘Trigger’) as shown in the image below.

To Create a new Wave Trigger in the scene, click the ‘+’ button on the Wave Triggers section of the Runtime Spawner UI. This will automatically add a child game object for the Runtime Spawner and add the required components (Wave Trigger / Box Collider).
Properties
Wave Spawn Point
The Wave Spawn Point component defines the location where AI Agents that have been spawned by a Wave (as triggered by the Wave Trigger component, above) will be spawned in the world.
Properties
Spawn Range
Defines a spawn area for this spawn point. A random spot within the range will be used to spawn the AI Agents. This range is visible as a scene view gizmo as shown below.
Fundamentals
WaveTrigger is a trigger volume that activates a WaveSpawner sequence when the player enters its collider. It supports optional reactivation after a cooldown and provides editor helpers for authoring spawn points.
Use a WaveTrigger to drive:
Scriptable wave encounters (hordes, ambushes, defense events).
One-shot or repeatable combat arenas.
Waves that start on player approach or automatically on level start.
Requirements
A
BoxCollideron the same GameObject.BoxCollider.isTriggermust be enabled.A
RuntimeSpawnermust exist in the scene (the trigger registers with it at runtime).A
WaveSpawnerasset assigned to configure the waves.
The collider is auto-assigned to TriggerZone in OnEnable().
Responsibilities
Detect activators (by tag) entering the trigger volume.
Activate the configured
WaveSpawnervia the centralRuntimeSpawner.Optionally auto-start on scene load.
Optionally re-arm after a cooldown to allow repeated encounters.
Provide optional
WaveSpawnPointanchors to control spawn locations.
Key Properties
Trigger and state
BoxCollider TriggerZoneThe collider used as the activation volume. Auto-assigned inOnEnable().int ActiveWaveThe current wave index (0-based) being spawned for this trigger. Managed by the wave runner / RuntimeSpawner.bool IsActivatedIndicates whether this trigger is currently active:truewhile a sequence is running, or when marked active.Set to
falsewhen reset or before first activation.
Wave configuration
WaveSpawner WaveSpawnerThe wave table used when this trigger activates. Must be assigned for the trigger to function in play mode.List<WaveSpawnPoint> WaveSpawnPointsOptional anchor points used during wave spawning. When present, spawn locations are chosen among these anchors (selection handled by the wave system).
Activation & reactivation (serialized)
bool startAutomaticallyWhen enabled, the trigger activates automatically after both:RuntimeSpawneris initialized, andWaveTriggerhas started.
string playerTagTag of GameObjects that can activate the trigger when entering the volume (defaults to"Player").bool reactivateTriggerWhen enabled, the trigger will automatically reset after a cooldown and can be activated again.float reactivateTimeTime in seconds before the trigger resets and becomes eligible for activation again.
Events
public static event Action<WaveTrigger> onWaveTriggerActivated;
public static event Action<WaveTrigger> onWaveTriggerReset;onWaveTriggerActivatedInvoked when this trigger activates.RuntimeSpawnerlistens to this event to start the wave sequence.onWaveTriggerResetInvoked after the cooldown when the trigger becomes eligible for reactivation (ifreactivateTriggeris enabled).
Runtime Behaviour
Initialization and registration
On enable:
Subscribes to
RuntimeSpawner.onSpawnerInit(play mode only) to detect when the spawner is ready.Ensures
TriggerZoneis assigned and set toisTrigger = true.If a
RuntimeSpawnerreference already exists, registers this trigger withRegisterWaveTrigger.
On disable:
Unsubscribes from
RuntimeSpawner.onSpawnerInit.Unregisters from
RuntimeSpawnerif previously registered.
On start (play mode):
If
WaveSpawneris not set, no further initialization occurs.Locates a
RuntimeSpawner(FindAnyObjectByType<RuntimeSpawner>()).Registers with the spawner via
spawner.RegisterWaveTrigger(this).Synchronizes
initializedwithspawner.IsInitialized.If
startAutomaticallyis enabled, beginsActivateWhenReady()to auto-fire once the spawner reports ready.
Automatic activation
ActivateWhenReady():
Waits until
spawner.IsInitialized == true.If the spawner never initializes, logs an error and exits.
If
IsActivatedis alreadytrue, exits to avoid double-firing.Marks
IsActivated = trueand invokesonWaveTriggerActivated(this).
Volume-based activation
OnTriggerEnter(Collider other):
Only runs in play mode.
Ignores activation if:
IsActivatedis alreadytrue,No
RuntimeSpawnerexists, or it is not initialized,The entering collider does not match
playerTag.
When all conditions are satisfied:
Sets
IsActivated = true.Invokes
onWaveTriggerActivated(this).If
reactivateTriggeris enabled, starts the reactivation coroutine.
Reactivation
ResetTrigger():
Public method to start a reset cycle from scripts or editor buttons.
Starts the
TimeToReset()coroutine.
TimeToReset():
Waits for
reactivateTimeseconds.Sets
IsActivated = false.Invokes
onWaveTriggerReset(this).
This allows repeatable trigger behaviour when reactivateTrigger is enabled.
Editor Helpers
These members assist with authoring in the Scene view (editor only):
public void AddSpawnpoint()Creates a new child
WaveSpawnPointunder this trigger.Positions it at the last spawn point’s position (if present), otherwise at the trigger’s position.
Adds it to
WaveSpawnPointsand selects it in the hierarchy.
public void ShowHide(bool showHide)Controls whether the trigger volume gizmo is drawn in the Scene view.
OnDrawGizmos():
Draws the
TriggerZonevolume whenshowHideTriggeris enabled.Uses
RuntimeSpawnerSettings.waveTriggerColorby default.Uses a different color when
IsActivatedistrue.
Typical Usage Patterns
1. One-shot encounter volume
A basic encounter that fires once when the player enters a room:
Add a
WaveTriggerGameObject to the scene.Add/ensure:
BoxColliderwithisTrigger = trueWaveTrigger
Assign:
WaveSpawnerasset in the inspector.Optional
WaveSpawnPointsusing the “Add Spawnpoint” editor button.
Leave:
startAutomatically = falsereactivateTrigger = false
When the player (matching
playerTag) enters the volume:The trigger activates.
RuntimeSpawnerbegins the configured wave sequence.The trigger will not fire again unless reset manually.
2. Repeatable horde zone
A zone that can be revisited and re-challenged after a cooldown:
Configure the
WaveTriggeras above.Set:
reactivateTrigger = truereactivateTime = 30(for example)
Each time the player enters:
If not currently active, the trigger activates and starts waves.
After the sequence and cooldown, the trigger resets and can be activated again on re-entry.
Optional: hook into onWaveTriggerReset to update UI or minimap icons when the encounter becomes available again.
3. Auto-start level wave
A wave sequence that starts automatically after the spawner is initialized (e.g., survival mode opening wave):
Configure the
WaveTriggerwith aWaveSpawner.Set:
startAutomatically = truereactivateTriggeras desired (for repeat or one-shot).
When play begins:
The trigger waits until
RuntimeSpawner.IsInitializedreportstrue.The trigger activates and starts the wave sequence without requiring a player collider.
This pattern works well for scripted intro fights or survival modes that begin immediately.
4. Manual activation via script
To start a wave from code (e.g., from a console interaction or a UI button), call through the RuntimeSpawner:
using UnityEngine;
using MegaCrush.Spawner;
public class WaveConsole : MonoBehaviour
{
[SerializeField] private RuntimeSpawner spawner;
[SerializeField] private WaveTrigger trigger;
public void ActivateFromConsole()
{
if (spawner == null || trigger == null)
return;
// Uses the same flow as trigger activation
spawner.ActivateWaveTrigger(trigger);
}
}Attach
WaveConsoleto an in-world console or UI button.Wire
ActivateFromConsoleto the interaction (OnClick, input event, etc.).The wave will start using the same internal path as volume-based activation.
5. Listening for trigger activation/reset
To react to wave trigger lifecycle globally:
using UnityEngine;
using MegaCrush.Spawner;
public class WaveTriggerMonitor : MonoBehaviour
{
private void OnEnable()
{
WaveTrigger.onWaveTriggerActivated += HandleActivated;
WaveTrigger.onWaveTriggerReset += HandleReset;
}
private void OnDisable()
{
WaveTrigger.onWaveTriggerActivated -= HandleActivated;
WaveTrigger.onWaveTriggerReset -= HandleReset;
}
private void HandleActivated(WaveTrigger trigger)
{
Debug.Log($"WaveTrigger activated: {trigger.name}");
// Example: update HUD, lock doors, start encounter music
}
private void HandleReset(WaveTrigger trigger)
{
Debug.Log($"WaveTrigger reset: {trigger.name}");
// Example: show “encounter available” marker again
}
}This pattern integrates wave encounters with UI, audio, and other gameplay systems.
Last updated