Enemy Masses Crowd Controller

The EnemyMassesCrowdController is the central brain of the Enemy Masses system. It manages all crowd agents, handles spawning, coordinates AI behavior, and optimizes performance. You typically need exactly one of these in your scene.

Core Setup

These settings define the fundamental configuration of your crowd system.

Enemy Crowd Factions

  • Description: A list of EnemyCrowd ScriptableObjects that this controller will manage.

  • Usage: Drag and drop your created EnemyCrowd assets here. Each asset represents a distinct type of enemy (e.g., "Orc Grunt", "Zombie Walker") with its own stats, prefab, and behavior settings.

  • Why use it: Essential. Without assigning crowds here, the controller doesn't know what to spawn.

Player Target

  • Description: The Transform that enemy agents will target and chase.

  • Usage: Assign your player's main GameObject or a specific target point (like the chest or head).

  • Why use it: Required for Combat Crowds. If left empty, enemies won't have a default target to attack.

  • When not to use: For Civil Crowds or RTS Battle Simulations where units target each other or wander freely, this is less critical but still good practice to assign for fallback behavior.


Global Settings

These settings apply to all agents managed by this controller, regardless of their faction. They are primarily focused on system-wide performance and limits.

Performance Settings

  • Description: Controls how aggressively the system optimizes agent updates to maintain frame rate.

  • Presets:

    • None: No optimization. Updates every agent every frame. Best for small crowds (< 100).

    • Moderate: Light throttling. Good balance for medium crowds (100-300).

    • Aggressive: Stronger throttling. Updates distant agents less frequently. Good for large crowds (300-1000).

    • Very Aggressive: Maximum optimization. Distant agents update rarely. Essential for massive crowds (1000+).

    • Custom: Exposes fine-grained controls for update intervals, priority distances, and fractions per frame.

  • Why use it: To keep your game running smoothly as agent counts increase.

  • When not to use: Use "None" only for cinematic renders or very small skirmishes where perfect animation smoothness is more important than performance.

Hit Detection Mode

  • Description: Determines how attacks register hits on the player.

  • Options:

    • Distance: Uses virtual hitboxes and distance checks. Extremely fast.

    • Collider: Uses Unity's physics engine (Colliders/Triggers). More accurate but more expensive.

  • Why use Distance: For massive crowds where thousands of physics checks would kill performance.

  • Why use Collider: If you need precise hit detection (e.g., dodging specific weapon swings) and have a manageable agent count.

Animation Culling

  • Description: Stops processing animations for agents that are too far away.

  • Settings:

    • Cull By Distance: Enables the feature.

    • Distance: The range (in meters) beyond which animations stop updating.

    • Reference: The object to measure distance from (usually the Main Camera).

  • Why use it: Animation processing is often the biggest bottleneck. Culling distant agents can double your frame rate.

  • When not to use: If you have a top-down game where all visible units must be animated, or if the popping effect of animations stopping is too noticeable.

Audio Settings

  • Description: Limits the number of footstep sounds playing simultaneously.

  • Settings:

    • Max Footsteps Per Frame: How many new footstep sounds can start in a single frame.

    • Max Global Sources: The hard limit on total concurrent footstep AudioSources.

  • Why use it: To prevent "audio spam" where hundreds of footsteps create a wall of noise and degrade performance.

  • When not to use: You should almost always use this. The default values are usually good.

Spawn Settings

  • Description: Technical configuration for the GPU Instancer integration.

  • Settings:

    • Prefab Manager: Reference to the GPUIPrefabManager in the scene. Auto-assigned by the Setup Wizard.

    • Register Immediately: If true, agents are added to the rendering system the moment they spawn.

  • Why use it: "Register Immediately" ensures agents are visible instantly, preventing a "pop-in" effect.

  • When not to use: If you are spawning thousands of units at start and want to spread the registration load over several frames to prevent a lag spike.


Runtime Controls (Play Mode Only)

When the game is running, the Inspector shows additional debugging tools:

  • Spawn Controls: Manually spawn specific factions and counts for testing.

  • Stress Tests: Buttons to instantly spawn 1k, 5k, or 10k units to test performance limits.

  • Debug Info: Shows active agent counts and system status.


Control Tab (Faction Battles)

The Control tab is dedicated to the Faction Battle Mode, a powerful feature for creating large-scale battles between AI armies or testing combat scenarios without player involvement.

Faction Battle Mode

  • Description: Switches the AI logic from "Player vs. Enemy" to "Enemy vs. Enemy".

  • Enable Faction Battle:

    • On: Agents ignore the Player Target and attack agents from other factions.

    • Off: Agents behave normally (attacking the Player Target or following Civil logic).

  • Battle Type:

    • FactionVsFaction: Teams fight based on their faction (e.g., Orcs vs. Humans).

    • AllVsAll: Every agent fights for themselves (Battle Royale style).

  • Target Update Interval: How often (in seconds) agents re-evaluate their targets. Lower values make battles more dynamic but cost more CPU.

  • Max Target Updates/Frame: Limits how many agents search for new targets per frame to prevent lag spikes during massive battles.

Why use it?

  • Testing: Quickly verify combat animations and damage balancing by making two factions fight.

  • Cinematics: Create epic background battles for cutscenes.

  • Gameplay: Build RTS-style scenarios or "Battle Simulator" modes where the player watches or commands armies.

Runtime Battle Controls

When in Play Mode, this tab exposes additional buttons:

  • Start/Stop Battle: Toggles the fighting on/off dynamically.

  • Battle Status: Shows live stats like "Red Team: 50 alive, Blue Team: 20 alive".

Last updated