ufo-beamSpawning Systems

Enemy Masses provides two primary components for spawning crowds without writing any code: Start Spawner and Spawn Trigger. Both components are designed to be drag-and-drop solutions for level design.

Common Settings

Both components share a core set of spawn configuration options:

  • Crowd Controller: Reference to the scene's EnemyMassesCrowdController.

  • Enemy Crowd Index: The ID of the faction to spawn (0 = First faction in the Controller's list, 1 = Second, etc.).

  • Spawn Count: How many agents to spawn.

  • Spawn Formation: The shape of the spawn group (Circle, Box, Line, etc.).

  • Spawn Location: A Transform defining where the center of the crowd will appear. If left empty, it uses the component's own Transform.


Start Spawner

The EnemyMassesStartSpawner is a utility component designed to populate your scene with enemy crowds as soon as the game begins. It provides a simple, visual way to place armies, guards, or ambient crowds without writing initialization code.

Overview

This component handles the instantiation of a specific crowd faction at a specific location when the scene loads (specifically in the Start() method). It also includes powerful editor visualization tools to let you see exactly how the formation will look before you press Play.

Key Features

  • Auto-Spawn: Spawns automatically on Start().

  • Formation Preview: Draws a gizmo showing the exact position of every single agent in the formation (up to 256 agents for preview performance).

  • Post-Spawn Logic: Can automatically command the spawned unit to move to a destination or attack a target immediately.

  • Manual Control: Can be triggered manually via script if you disable the "Spawn On Start" option.

Setup Guide

  1. Create the Spawner Object:

    • Create an Empty GameObject in your scene.

    • Name it something descriptive, e.g., Spawner_CastleGuards.

  2. Add the Component:

    • Add the EnemyMassesStartSpawner component.

  3. Link the Controller:

    • Assign your scene's EnemyMassesCrowdController to the Crowd Controller field.

  4. Select the Faction:

    • Enemy Crowd Index: Enter the index of the faction you want to spawn (corresponding to the list in your Crowd Controller).

    • Visual Feedback: The Gizmo color will update to match the faction's color.

Configuration

Spawn Settings

  • Crowd Controller: The manager responsible for the actual spawning.

  • Enemy Crowd Index: The ID of the faction to spawn.

  • Spawn Count: The total number of agents to spawn.

  • Spawn Formation: The geometric shape of the unit.

    • Circle: Agents form a filled circle.

    • Box: Agents form a solid rectangle.

    • Line: Agents form a wide line (good for battle fronts).

    • Ring: Agents form a hollow ring.

  • Spawn Formation Spacing: Overrides the default spacing defined in the EnemyCrowd asset. Set to 0 to use the asset's default.

  • Spawn On Start:

    • True: Spawns automatically when the scene loads.

    • False: Waits for a manual call to SpawnNow().

  • Spawn Once: If true, prevents the component from spawning a second time (useful if you are toggling the GameObject on/off).

Spawn Location

  • Spawn Location: A Transform defining the center point and rotation of the formation.

  • Use This Transform If No Location: If checked and Spawn Location is empty, uses the component's own Transform.

Post Spawn Behavior

Define what the crowd does immediately after appearing.

  • Auto Set Destination:

    • True: Agents will try to move to a specific point.

    • Destination Override: The Transform to move to. If empty, they will try to move to their spawn point (useful for correcting formation drift).

  • Auto Attack Target:

    • True: Agents will immediately aggro onto a target.

    • Attack Target: The specific Transform to attack. If empty, they defaults to the Player Target defined in the Crowd Controller.

Visual Gizmos

The EnemyMassesStartSpawner features advanced editor visualization to help with level design.

  • Formation Preview: Small dots represent individual agents, showing you the exact shape, size, and density of the crowd.

    • Note: The preview is capped at 256 agents to prevent editor lag. If you spawn 10,000 agents, the preview will only show the first 256 to give you an idea of the density.

  • Direction Arrow: A large arrow indicates the "Forward" direction of the formation (crucial for Box and Line formations).

  • Destination Line: If a Destination Override is set, a dotted line connects the spawn point to the destination, visualizing the path the crowd will take.

Scripting API

If you disable Spawn On Start, you can control the spawner programmatically:

Dynamic Configuration

You can also modify settings via script before spawning:


Spawn Trigger

The EnemyMassesSpawnTrigger is a powerful component designed to create dynamic encounters, ambushes, and wave-based events without writing a single line of code. It handles the logic of detecting players or objects and spawning a specific crowd faction in response.

Overview

This component combines a Trigger Zone (Collider) with a Spawner. When a valid object enters the zone, the component instructs the EnemyMassesCrowdController to spawn a new group of enemies.

Key Features

  • Auto-Collider Management: Automatically creates and manages its own Box, Sphere, or Capsule collider.

  • Flexible Filtering: Trigger on Player, Tags, Layers, or specific combinations.

  • Visual Feedback: Color-coded gizmos in the Scene View match the faction color, showing exactly where the trigger is and where enemies will spawn.

  • Combat Integration: Can automatically command spawned enemies to attack the specific object that tripped the alarm.

Setup Guide

  1. Create the Trigger Object:

    • Create an Empty GameObject in your scene (or use a primitive like a Cube if you want a visible marker, then disable its MeshRenderer).

    • Name it something descriptive, e.g., Trigger_Ambush_Orcs.

  2. Add the Component:

    • Add the EnemyMassesSpawnTrigger component.

    • Note: You do not need to add a Collider manually. The component will add one for you based on the Trigger Shape setting.

  3. Link the Controller:

    • Assign your scene's EnemyMassesCrowdController to the Crowd Controller field.

  4. Select the Faction:

    • Enemy Crowd Index: Enter the index of the faction you want to spawn.

    • Tip: The Gizmo color will update to match the faction's color defined in its EnemyCrowd asset.

Configuration

Trigger Settings

  • Crowd Controller: The manager responsible for the actual spawning.

  • Enemy Crowd Index: The ID of the faction to spawn (0 = First faction, 1 = Second, etc.).

  • Spawn Count: How many agents to spawn.

  • Spawn Formation: The geometric arrangement of the spawned unit (Circle, Box, Line, etc.).

Spawn Location

  • Spawn Location: A Transform defining where the center of the crowd will appear.

    • Best Practice: Create a child GameObject, move it to where you want the enemies to appear, and assign it here. This separates the Trigger Zone (where the player walks) from the Spawn Point (where enemies appear).

  • Use This Transform If No Location: If checked and Spawn Location is empty, enemies spawn directly on top of the trigger object.

Trigger Filters

Control what activates the trigger.

  • Activation Type:

    • PlayerTarget: Triggers only when the specific Player Transform (defined in the Crowd Controller) enters. This is the most performant and common option.

    • Tag: Triggers when any object with the Required Tag enters.

    • Layer: Triggers when any object on the Required Layer enters.

    • TagAndLayer: Must match both.

    • TagOrLayer: Matches either.

    • Any: Triggers on anything (use with caution).

Trigger Behavior

  • Trigger Shape:

    • Box: Creates a BoxCollider.

    • Sphere: Creates a SphereCollider.

    • Capsule: Creates a CapsuleCollider.

    • Note: Changing this automatically updates the Collider component on the GameObject.

  • Trigger Once:

    • True: The trigger fires once and then disables itself.

    • False: The trigger can fire repeatedly.

  • Trigger Cooldown: If Trigger Once is false, this sets the minimum time (in seconds) between spawns.

Post-Spawn Logic

  • Auto Set Destination: If true, enemies will move to the spawn location (useful if they spawn slightly offset).

  • Auto Attack Triggering Object:

    • If True: The spawned crowd immediately targets the specific object that entered the trigger.

    • Example: If a specific NPC walks into the trap, the enemies attack that NPC, not necessarily the Player.

Visual Gizmos

The component draws extensive debug information in the Scene View to help you design your level.

  • Trigger Zone: Drawn as a wireframe shape (Box/Sphere/Capsule).

  • Spawn Point: Drawn as a wire sphere with a directional arrow showing the formation's forward facing.

  • Connection Line: A dotted line connects the Trigger to the Spawn Point, helping you see the relationship between "Cause" and "Effect".

  • Color Coding: All gizmos are tinted with the Faction Color of the selected Enemy Crowd.

    • Red Gizmo = Spawns Red Faction.

    • Blue Gizmo = Spawns Blue Faction.

Scripting API

If you need to control the trigger from your own scripts:

Spawn Interval

The EnemyMassesSpawnInterval component provides interval-based or wave-based spawning for Enemy Masses crowds. It's ideal for survival modes, tower defense scenarios, or any game that needs continuous enemy reinforcements at regular intervals.


Features

  • Interval Spawning: Spawn waves of enemies at configurable time intervals

  • Wave Limits: Set a maximum number of waves or spawn infinitely

  • Start Delay: Optional delay before the first wave spawns

  • Formation Support: Spawn units in any formation type with custom spacing

  • Post-Spawn Behavior: Automatically set destinations or attack targets after spawning

  • Visual Preview: Editor gizmos show spawn location, direction, and formation layout

  • Runtime Control: Start, stop, and manually trigger spawns via script


Quick Setup

  1. Create an empty GameObject in your scene

  2. Add the EnemyMassesSpawnInterval component (or use GameObject > Enemy Masses > Spawn Interval)

  3. Assign the Crowd Controller reference

  4. Set the Enemy Crowd Index to the faction you want to spawn

  5. Configure Spawn Count and Spawn Interval

  6. Play the scene!

circle-info

If Start Spawning On Start is enabled (default), spawning begins automatically when the scene starts.


Settings Reference

Spawn Settings

Setting
Description
Default

Crowd Controller

The EnemyMassesCrowdController that manages spawning

-

Enemy Crowd Index

Index of the enemy crowd/faction to spawn (from Enemy Crowds list)

0

Spawn Count

Number of agents to spawn per wave

50

Spawn Formation

Formation type for spawned agents

Circle

Spawn Formation Spacing

Spacing override (0 = use faction default)

0

Start Spawning On Start

Automatically begin spawning in Start()

true

Interval Settings

Setting
Description
Default

Start Delay

Seconds to wait before the first wave

0

Spawn Interval

Seconds between each wave

5

Max Waves

Maximum waves to spawn (0 = infinite)

0

circle-info

Set Max Waves to 0 for endless spawning (survival mode), or set a specific number for scripted encounters.

Spawn Location

Setting
Description
Default

Spawn Location

Transform defining spawn position and rotation

-

Use This Transform If No Location

Use this GameObject's transform if no location assigned

true

circle-info

The spawn location's rotation determines the direction units face when spawned. Use this to point spawned units toward the player or a strategic location.

Post-Spawn Behavior

Setting
Description
Default

Auto Set Destination

Automatically set a destination after spawning

true

Destination Override

Explicit destination (if null, uses spawn position)

-

Auto Attack Target

Spawned units automatically attack a target

false

Attack Target

Explicit attack target (falls back to PlayerTarget if null)

-

circle-exclamation

Visual Feedback

Setting
Description
Default

Show Gizmos

Display spawn location and formation preview in editor

true

Show Formation Preview

Show individual unit positions in formation

true

Custom Gizmo Color

Override the auto-assigned faction color

Clear (auto)


Post-Spawn Behavior Explained

After each wave spawns, the component can automatically configure the new units:

Auto Set Destination

When enabled, spawned units immediately receive a move command:

  • With Destination Override: Units move toward the assigned Transform

  • Without Destination Override: Units stay at spawn position (useful with formations)

Auto Attack Target

When enabled, spawned units enter attack mode targeting:

  1. Explicit Attack Target (if assigned)

  2. Nearest PlayerTarget (fallback) - automatically finds the closest player-controlled unit or structure

This is ideal for tower defense games where enemies should immediately aggro the player base.


Runtime Control

Properties

Property
Type
Description

IsSpawning

bool

True if currently running the spawn loop

WavesSpawned

int

Number of waves spawned so far

Methods


Scripting Examples

Basic Wave Controller

Scaling Difficulty

Triggered Spawning

Multiple Spawn Points

Event-Based Wave Completion


Editor Gizmos

The component displays helpful visual feedback in the Scene view:

Visual
Description

Wire Sphere

Spawn center point

Wire Circle

Spawn area boundary

Directional Arrow

Direction units will face

Small Spheres

Individual unit positions in formation

Dashed Line

Path to destination (if Destination Override set)

circle-info

Gizmo colors are automatically assigned based on Enemy Crowd Index for easy visual distinction between multiple spawners. Use Custom Gizmo Color to override.


Common Use Cases

Survival Mode (Endless Waves)

Tower Defense (Attack Base)

Scripted Encounter (Limited Waves)

Reinforcement Spawner


Performance Tips

  1. Spawn Count: Keep wave sizes reasonable (50-200) to avoid frame spikes

  2. Spawn Interval: Allow time between waves for the crowd system to stabilize

  3. Formation Preview: Disable Show Formation Preview for spawners with large spawn counts (256+)

  4. Multiple Spawners: Stagger spawn timing to spread load across frames

Spawn Patrol

The EnemyMassesSpawnPatrol component spawns enemy crowds and keeps them continuously patrolling. It supports both free-roam patrol (random movement within a radius) and waypoint-based patrol paths, with full formation support and combat awareness.


Features

  • Patrol Modes: Free-roam within a radius or follow defined waypoints

  • Formation-Aware: Units maintain formation spacing while patrolling

  • Combat Awareness: Patrols pause automatically during combat

  • Spawn Modes: Spawn once at start, at intervals, or manually via script

  • Force Formation: Override the EnemyCrowd's formation settings per-spawner

  • Central Scheduler: Efficient update distribution across many patrol groups

  • Visual Preview: Editor gizmos show spawn location, patrol area, and waypoints


Quick Setup

  1. Create an empty GameObject in your scene

  2. Add the EnemyMassesSpawnPatrol component (or use GameObject > Enemy Masses > Spawn Patrol)

  3. Assign the Crowd Controller reference

  4. Set the Enemy Crowd Index to the faction you want to spawn

  5. Choose your Patrol Mode (FreeRoam or Waypoints)

  6. Configure patrol area or add waypoints

  7. Play the scene!

circle-info

By default, the component spawns units once at scene start. Change Spawn Mode to Interval for wave-based spawning or Manual for scripted control.


Settings Reference

Spawn Settings

Setting
Description
Default

Crowd Controller

The EnemyMassesCrowdController that manages spawning

-

Enemy Crowd Index

Index of the enemy crowd/faction to spawn

0

Spawn Count

Number of agents to spawn per wave

50

Spawn Formation

Formation type for spawned agents

Circle

Spawn Formation Spacing

Spacing override (0 = use faction default)

0

Force Spawner Formation

Override the EnemyCrowd's Override Formation setting

false

circle-info

Force Spawner Formation is useful when your EnemyCrowd has Override Formation enabled, but you want this specific spawner to use a different formation. The spawner's formation will be used instead.

Spawn Timing

Setting
Description
Default

Spawn Mode

When to spawn: StartOnStart, Interval, or Manual

StartOnStart

Start Delay

Seconds to wait before first spawn

0

Spawn Interval

Seconds between waves (Interval mode only)

8

Max Waves

Maximum waves to spawn, 0 = infinite (Interval mode only)

0

Spawn Location

Setting
Description
Default

Spawn Location

Transform defining spawn position and rotation

-

Use This Transform If No Location

Use this GameObject's transform if no location assigned

true

Patrol Settings

Setting
Description
Default

Patrol Mode

FreeRoam (random in radius) or Waypoints (defined path)

FreeRoam

Patrol Center

Center point for free roam (null = spawn position)

-

Patrol Radius

Radius for free roam patrol

25

Patrol Arrival Distance

Distance considered "arrived" at patrol point

1.5

Patrol Min Target Distance

Minimum distance between patrol targets (0 = auto)

0

Patrol Wait Time

Seconds to wait at each patrol point

0

Patrol Update Interval

How often to evaluate patrol state

0.25

Use Formation For Patrol

Keep formation while patrolling

true

Pause Patrol When Engaged

Pause patrol during combat

true

Waypoint Settings

Setting
Description
Default

Patrol Waypoints

List of Transform waypoints to visit

Empty

Loop Waypoints

Loop back to first waypoint after last

true

Randomize Waypoints

Pick next waypoint randomly

false

Performance Settings

Setting
Description
Default

Stagger Patrol Updates

Randomize initial update timing

true

Use Central Scheduler

Use shared scheduler for many spawners

true

Central Scheduler Max Spawners Per Frame

Max spawners processed per frame

3

Combat Settings

Setting
Description
Default

Enable Faction Battle Mode

Enable faction-vs-faction combat

true

Visual Feedback

Setting
Description
Default

Show Gizmos

Display spawn and patrol gizmos

true

Show Formation Preview

Show formation unit positions

true

Show Patrol Radius

Show patrol radius (FreeRoam mode)

true

Custom Gizmo Color

Override auto-assigned faction color

Clear (auto)


Patrol Modes Explained

Free Roam Mode

Units patrol randomly within a circular area:

  • Patrol Center: If set, units patrol around this transform. Otherwise, they patrol around their spawn position.

  • Patrol Radius: Defines how far units can wander from the center.

  • Min Target Distance: Prevents units from receiving patrol targets too close to their current position (reduces jittery movement).

Waypoints Mode

Units follow a defined path of waypoints:

  • Sequential: Units visit waypoints in order (1 → 2 → 3 → 4 → 5 → 1...)

  • Random: Units pick the next waypoint randomly

  • Loop: After the last waypoint, return to the first

  • No Loop: Units stop at the last waypoint


Formation Control

Force Spawner Formation

When your EnemyCrowd asset has Override Formation enabled, it normally forces all spawned units to use its formation type. The Force Spawner Formation option lets you bypass this:

Force Spawner Formation
EnemyCrowd Override Formation
Result

false

false

Uses spawner's formation

false

true

Uses EnemyCrowd's formation

true

false

Uses spawner's formation

true

true

Uses spawner's formation ✓

circle-info

This is useful for creating variety. Your EnemyCrowd might default to Rectangle formation, but a specific ambush spawner could use Circle or Line formation.

Formation While Patrolling

When Use Formation For Patrol is enabled:

  • Units maintain their formation spacing at each patrol point

  • The group moves as a cohesive unit

  • Formation is calculated based on Spawn Formation and Spawn Formation Spacing

When disabled:

  • Units move independently to patrol points

  • May result in spread-out, less organized patrol patterns


Combat Behavior

Pause Patrol When Engaged

When enabled, the patrol system monitors each spawn group for combat activity:

  1. Detection: Any unit in the group becomes aggroed or has an attack target

  2. Pause: Patrol movement stops for the entire group

  3. Fight: Units engage enemies normally

  4. Resume: Once all units are no longer engaged, patrol resumes

This prevents patrols from wandering away mid-combat.

Faction Battle Mode

When Enable Faction Battle Mode is enabled, the component sets crowdController.FactionBattleMode = true after spawning. This enables:

  • Automatic enemy detection between factions

  • Cross-faction combat when patrol groups encounter each other

  • Proper aggro sharing within spawn groups


Spawn Modes

StartOnStart

Units spawn once when the scene starts (after optional delay):

Interval

Units spawn in waves at regular intervals:

Manual

No automatic spawning. Call SpawnNow() from script:


Runtime Control

Properties

Property
Type
Description

IsSpawning

bool

True if running the spawn loop (Interval mode)

WavesSpawned

int

Number of waves spawned so far

Methods


Performance Optimization

Central Scheduler

When you have many patrol spawners in a scene, the Central Scheduler distributes updates across frames to prevent performance spikes:

Setting
Effect

Use Central Scheduler = true

Updates are distributed across frames

Central Scheduler Max Spawners Per Frame = 3

At most 3 spawners update per frame

With 30 patrol spawners and Max Spawners Per Frame = 3:

  • All spawners share a single scheduler

  • Updates spread across ~10 frames

  • Prevents 30 patrol evaluations in a single frame

Stagger Patrol Updates

When enabled, each spawner's initial patrol update is randomized within its Patrol Update Interval. This prevents all spawners from updating on the same frame at scene start.


Scripting Examples

Basic Patrol Spawner

Dynamic Waypoints

Triggered Patrol Spawn

Multiple Patrol Routes


Editor Gizmos

The component displays helpful visual feedback in the Scene view:

Visual
Description

Wire Sphere (small)

Spawn point

Directional Arrow

Direction units face when spawned

Wire Sphere (large)

Patrol radius (FreeRoam mode)

Waypoint Spheres

Waypoint positions (Waypoints mode)

Connecting Lines

Path between waypoints

Small Spheres

Formation preview positions

circle-info

Gizmo colors are automatically assigned based on Enemy Crowd Index. Use Custom Gizmo Color to override for specific spawners.


Debugging

Enable debug logs to diagnose patrol issues:

Setting
Description

Debug Patrol Logs

Log patrol state transitions and arrivals

Debug Patrol Verbose

Include per-agent navigation details

Debug Patrol Log Interval

Seconds between log entries

Debug output includes:

  • Patrol target assignments

  • Group arrival detection

  • Combat pause/resume events

  • NavMesh path status

  • Agent navigation state changes


Common Use Cases

Wandering Guards

Perimeter Patrol

Random Patrol (Unpredictable)

Ambush Point


Spawn Around Target

The EnemyMassesSpawnAroundTarget component provides a flexible way to spawn enemy crowds at random positions within a configurable radius around a target transform. It's ideal for creating dynamic spawn scenarios such as ambushes, reinforcements, or surrounding the player.

Overview

This component spawns agents from an assigned EnemyMassesCrowdController at randomized positions around a specified target. Spawned agents are automatically placed on valid NavMesh positions and can be configured to immediately attack or move toward the target.


Properties

Spawn Settings

Property
Type
Description

Crowd Controller

EnemyMassesCrowdController

The crowd controller that will spawn agents.

Enemy Crowd Index

int

Which enemy crowd faction to spawn (index in the Enemy Crowds list).

Total Spawn Count

int

Total number of agents to spawn. Minimum: 1.

Spawn Mode

SpawnMode

How agents should be spawned around the target (see Spawn Modes).

Agents Per Wave

int

Number of agents per wave (used in IntervalWaves mode). Minimum: 1.

Spawn Formation

FormationType

Formation type for spawned agents.

Spawn Formation Spacing

float

Spacing override for this spawn. 0 = use faction default; non-zero overrides with absolute value.

Start Spawning On Start

bool

Automatically start spawning when the component's Start() is called.

Target Settings

Property
Type
Description

Target Transform

Transform

The target transform to spawn agents around.

Spawn Radius

float

Maximum radius around the target where agents can spawn. Minimum: 0.1.

Min Spawn Radius

float

Minimum distance from target center (creates a ring if > 0).

Uniform Distribution

bool

true = uniform distribution within the radius; false = more agents spawn near edges.

NavMesh Search Radius

float

Maximum vertical distance to search for a valid NavMesh point. Minimum: 0.1.

Interval Settings

Property
Type
Description

Start Delay

float

Delay in seconds before the first spawn.

Spawn Interval

float

Seconds between each spawn (for interval modes). Minimum: 0.01.

Post Spawn Behavior

Property
Type
Description

Auto Attack Target

bool

Automatically set the target as the attack destination after spawning.

Auto Move To Target

bool

If not attacking, set destination to target position.

Visual Feedback

Property
Type
Description

Show Gizmos

bool

Show spawn area gizmos in the editor.

Custom Gizmo Color

Color

Custom gizmo color. Leave as Color.clear for auto-color based on faction index.

Preview Point Count

int

Number of preview spawn points to show in the editor (0-50).


Spawn Modes

The component supports three spawning modes:

AllAtOnce

Spawns all agents immediately at random positions within the radius. Agents are spawned in batches (based on agentsPerWave) at different random positions to distribute them around the target.

IntervalWaves

Spawns agents in waves at regular intervals. Each wave contains agentsPerWave agents and appears at a random position within the spawn radius. Waves continue until totalSpawnCount is reached.

IndividualAtIntervals

Spawns individual agents one at a time at random positions within the radius. Each agent spawns at a different random location around the target at the configured spawnInterval.


Public Methods

StartSpawning()

Starts the spawning process based on the configured spawn mode. Only works in Play mode. Does nothing if spawning is already active or if all agents have been spawned.

StopSpawning()

Stops the spawning process immediately. Any agents already spawned remain in the scene.

ResetSpawnCounter()

Resets the spawn counter to allow spawning again after all agents have been spawned.

SpawnWaveNow()

Manually spawn a wave of agents at a random position around the target. Spawns agentsPerWave agents.

SpawnSingleNow()

Manually spawn a single agent at a random position around the target.

GetGizmoColor()

Returns the gizmo color used for visualization. Returns customGizmoColor if set, otherwise returns an auto-assigned color based on enemyCrowdIndex.


Public Properties

Property
Type
Description

IsSpawning

bool

Returns true if the spawning coroutine is currently active.

AgentsSpawned

int

Returns the total number of agents spawned so far.

RemainingAgents

int

Returns the number of agents remaining to spawn.


Usage Examples

Basic Setup

  1. Add the EnemyMassesSpawnAroundTarget component to a GameObject

  2. Assign your EnemyMassesCrowdController reference

  3. Set the targetTransform to the player or point of interest

  4. Configure totalSpawnCount and spawnRadius

  5. Enable startSpawningOnStart or call StartSpawning() manually

Scripted Spawning

Dynamic Target Following


Editor Visualization

When showGizmos is enabled, the component displays:

  • Outer Circle: The maximum spawn radius (colored by faction)

  • Inner Circle: The minimum spawn radius (if minSpawnRadius > 0)

  • Target Marker: Red sphere and crosshair at the target position

  • Preview Points: Sample spawn positions with direction arrows toward the target

  • Info Label: Displays spawn configuration when selected

The gizmo colors are automatically assigned based on enemyCrowdIndex:

  • Index 0: Red

  • Index 1: Blue

  • Index 2: Green

  • Index 3: Yellow

  • Index 4: Pink

  • Index 5: Purple

  • Index 6: Orange

  • Index 7: Cyan


Best Practices

  1. NavMesh Coverage: Ensure your NavMesh covers the spawn area. The component validates spawn positions against the NavMesh and will warn if no valid positions are found.

  2. Spawn Radius vs Formation Size: Consider the formation size when setting spawn radius. Large formations need more space to spawn properly.

  3. Performance: For large spawn counts with AllAtOnce mode, agents are spawned in batches to prevent frame drops.

  4. Ring Spawning: Use minSpawnRadius to create a ring-shaped spawn area, preventing agents from spawning directly on top of the target.

  5. Distribution: Enable uniformDistribution for evenly spread spawns, or disable it to concentrate more agents near the outer edge.


Troubleshooting

Issue
Solution

Agents not spawning

Verify crowdController and targetTransform are assigned. Check console for warnings.

"No valid NavMesh position found"

Ensure NavMesh is baked in the spawn area and navMeshSearchRadius is sufficient.

Agents spawning in wrong location

Verify targetTransform is at the correct position. Check that spawnRadius values are appropriate.

Spawning stopped early

Check if totalSpawnCount was reached. Use ResetSpawnCounter() to spawn again.


  • EnemyMassesCrowdController - Core crowd management

  • EnemyMassesSpawnInterval - Interval spawning without patrol

  • EnemyMassesStartSpawner - One-time spawning at scene start

  • EnemyMassesRTSController - Player control of units

  • FormationType

  • Spawning Overview


Last updated