Enemy Masses RTS Controller
Enemy Masses RTS Controller
The EnemyMassesRTSController is the core component for player interaction in an RTS game built with Enemy Masses. It handles unit selection, movement commands, formations, attack orders, and waypoint patrol paths. It is designed to work seamlessly with the EnemyMassesCrowdController to manage thousands of units efficiently.

Features
Selection System
Click Selection: Select individual units with a single click
Double-Click Selection: Select all units of the same type/faction on screen
Drag Selection: Classic RTS box selection for grouping units
Additive Selection: Hold Shift to add units to the current selection
Command System
Move Commands: Right-click to move selected units to a destination
Attack Commands: Right-click on an enemy unit to order an attack
Formations: Units automatically arrange themselves in formations at the destination
Advanced Formation Control
Drag-to-Adjust Spacing: Hold the command button and drag horizontally to adjust formation spacing before issuing the move order
Formation Rotation: Hold both command and selection buttons to rotate formation facing direction
Ghost Preview: Visualizes the formation shape and position before committing to the move
Formation Cycling: Scroll wheel or hotkey to cycle through formation types while previewing
Waypoint Patrol System
Queue Waypoints: Hold the queue modifier (Shift) while clicking to build patrol paths
Loop Closing: Click near the first waypoint to create a patrol loop
Ping-Pong Paths: Non-looped paths automatically reverse when reaching the end
Combat Awareness: Patrols auto-pause during combat and resume after combat ends
Visual Feedback: Waypoint markers and connecting lines (blue paths, green loops)
Formation-Aware: Patrol movement respects formation type and spacing
Additional Features
Faction Control: Restrict selection and commands to specific player-controlled factions
Fog of War Integration: Automatically hides non-player units when not visible
Group Bookmarks: Save and recall unit groups with number keys (0-9)
Input System Support: Fully supports Unity's New Input System and legacy Input Manager
Getting Started
Create an empty GameObject or use your existing "GameController" object
Add the
EnemyMassesRTSControllercomponentAssign the Crowd Controller reference (if not automatically found)
Assign the Target Camera (usually your Main Camera)
(Optional) Assign the Minimap Controller to prevent accidental deselection when clicking on the minimap
The controller automatically finds the EnemyMassesCrowdController and Camera.main if not explicitly assigned.
Key Settings
1. Selection Settings
Enable Click Selection
Toggles single-click selection
true
Enable Double Click Group Selection
Select all same-type units on double-click
true
Enable Drag Selection
Toggles box selection
true
Double Click Time
Time window for double-click detection
0.3s
Min Drag Distance
Pixels before drag selection starts
5
Agent Selection Mask
Layer mask for selectable objects
Everything
2. Command Settings
Enable Move Commands
Toggles right-click movement
true
Ground Mask
Layer mask for NavMesh/ground raycasts
Everything
Move Formation
Default formation type
Rectangle
Formation Spacing
Distance between units
1.5
Match Formation Speed To Slowest
Sync speed to slowest unit
false
3. Formation Settings
Enable Formation Cycling
Cycle formations while previewing
true
Use Mouse Scroll Wheel For Formation Cycle
Scroll to change formation
false
Enable Drag To Adjust Spacing
Drag to adjust density
true
Enable Rotation Adjustment
Drag to rotate formation
true
4. Input Settings
The controller supports both input systems:
New Input System:
Rebind Selection Button (Left Click), Command Button (Right Click), and modifiers directly in the Inspector
Uses
InputActionbindings
Legacy Input:
Uses standard mouse button indices (0, 1, 2) and KeyCodes
5. Visual Settings
Selection Rectangle Color
Color of the drag selection box
Selection Rectangle Border Color
Border color of the drag box
Move Indicator Prefab
Visual marker for move commands
Selection Indicator Prefab
Highlight ring under selected units
Ghost Formation Prefab
Preview marker for formation positions
6. Group Bookmarks
Select your agents, then hold the Control Group Save Modifier key and press 0-9
Press the group key to recall that selection
Double-press the group key to focus the camera on the group
Waypoint Patrol System
The patrol system allows you to create waypoint paths that units will continuously follow, with automatic combat handling and formation-aware movement.
Creating Patrol Paths
Select Units: Click or drag-select the units you want to patrol
Start Queuing: Hold the Queue Modifier (default: Left Shift)
Add Waypoints: While holding the modifier, click to add waypoints
Visualize Path: Blue lines connect waypoints as you add them
Complete Path: Either release the modifier (creates ping-pong path) or close the loop
Click near the first waypoint to close the loop and create a continuous patrol circuit. The loop closing distance is configurable via Patrol Loop Close Distance.
Patrol Path Types
Loop
Units patrol in a continuous circuit
Green connecting lines
Ping-Pong
Units patrol back and forth between waypoints
Blue connecting lines
Combat Behavior
When units on patrol enter combat:
Pause: The patrol is automatically paused
Combat Position: The interrupt position is stored
Fight: Units engage enemies normally
Resume: After combat ends, units resume patrol from current waypoint
Units resume patrol automatically after clearing enemies. They don't return to the interrupt position—they continue from where they are toward the next waypoint.
Formation-Aware Patrols
Patrol paths store formation data for each agent:
formationIndex
Agent's position in formation (0, 1, 2, ...)
formationTotalCount
Total agents in the patrol group
formationType
Formation type (Rectangle, Line, etc.)
formationSpacing
Spacing between agents
This means units maintain proper formation spacing at each waypoint, not clumping together.
Waypoint Patrol Settings
Enable Waypoint Patrol
Enable the patrol system
true
Waypoint Queue Modifier
Key to hold for queuing (New Input System)
Left Shift
Waypoint Queue Modifier Key
Key for queuing (Legacy Input)
LeftShift
Patrol Loop Close Distance
Distance to first waypoint to close loop
5
Show Waypoint Markers
Display markers at waypoints
true
Waypoint Marker Prefab
Prefab for waypoint markers
-
Waypoint Marker Offset
World-space offset for markers
(0, 0.1, 0)
Show Waypoint Lines
Draw lines connecting waypoints
true
Waypoint Line Color
Color for path lines
Blue
Waypoint Line Width
Width of path lines
0.15
Patrol Loop Line Color
Color for looped path lines
Green
Max Waypoints Per Path
Maximum waypoints allowed
20
Patrol APIs
AgentPatrolPath Class
Advanced Usage
Formation Dragging
This feature gives players precise control over unit positioning:
Select a group of units
Hold Right-Click (Command Button) at the target location
Drag Mouse Horizontally:
Ghost markers appear showing where units will go
Dragging expands or contracts formation spacing
Release Right-Click: Units move to the previewed positions
Formation Rotation
To face units in a specific direction:
Select units
Hold Right-Click (Command Button)
Hold Left-Click (Selection Button) while holding Right-Click
Drag Mouse: The formation rotates around its center
Release: Units move and rotate to face the new direction
Attack Targeting
Attack Target Mask
Ensure this includes layers your enemy units are on
Attack Target Click Radius
Since thousands of units might not have individual colliders, this radius helps detect clicks "near" a unit to register an attack command
Scripting Examples
Basic Selection and Commands
Listening to Selection Events
Custom Patrol Path Creation
Events Reference
SelectionChanged
SelectionChangedEventData
Fires when selection changes
onAgentSelected
int agentIndex
Single agent selected
onAgentDeselected
int agentIndex
Single agent deselected
onSelectionCleared
-
All agents deselected
MoveCommandIssued
Vector3 position, List<int> agents
Move command sent
onMoveCommandIssued
Vector3 position, List<int> agents
UnityEvent version
Integration Tips
Fog of War
Enable Render Above Fog to ensure destination indicators display above the fog plane
Set Indicator Sorting Order for proper layering
Minimap Integration
Assign your
RTSMinimapControllerto prevent deselection when clicking on the minimapThe controller automatically detects minimap clicks and ignores them for selection
Performance with Large Selections
Use Max Indicator Prefabs to limit selection highlights (20-100 for VFX, 500-2000 for lightweight UI)
Enable Shader Highlight for efficient selection visualization without spawning prefabs
The waypoint system efficiently handles thousands of agents with formation-aware pathing
Related Components
RTSCameraController - Camera controls for RTS games
RTS UI Components - Health bars, status effects, and command panels
EnemyMassesCrowdController - Core crowd management
Last updated