Automatic Music Transitions Based on Enemy Detection
Get dynamic battle music running in 5 minutes!
Select the Battle Music Component and in Details panel:
Add the tag Enemy to all enemy actors:
That's it! Music will automatically switch when enemies are nearby.
Music starts automatically when the game begins. Disable bAutoStart if you want manual control.
| Property | Default | Description |
|---|---|---|
| Calm Music | None | Sound asset for exploration/peaceful state |
| Battle Music | None | Sound asset for combat state |
| Detection Radius | 2000 cm (20m) | How far to detect enemies |
| Enemy Tag | "Enemy" | Tag used to identify enemies |
| Check Interval | 0.5 sec | How often to scan for enemies |
| Fade Time | 2.0 sec | Crossfade duration between tracks |
| State Cooldown | 1.0 sec | Minimum time between state changes |
| Auto Start | True | Start music on BeginPlay |
| Initial Volume | 1.0 | Starting volume (0.0-1.0) |
Different music for Boss/Elite/Regular enemies. Higher priority overrides lower.
Volume scales with enemy count. More enemies = louder music.
Resume tracks from last position instead of restarting.
Automatically ignore dead enemies (requires "Dead" tag).
| State | Condition | Music Playing |
|---|---|---|
| Calm | No enemies in detection radius | Calm Music track |
| Battle | One or more enemies detected | Battle Music (or custom priority music) |
| Fading | Transitioning between states | Crossfading between tracks |
CheckInterval seconds, performs sphere overlapEnemyTag within DetectionRadiusbIgnoreDeadEnemies enabled)| Property | Description |
|---|---|
| Detection Radius | Sphere radius in cm (2000 = 20 meters) |
| Enemy Tag | Tag to identify enemies (default: "Enemy") |
| Detection Channel | Collision channel for overlap (default: Visibility) |
| Check Interval | Seconds between scans (0.5 = twice per second) |
| Ignore Dead Enemies | Skip actors with "Dead" tag |
| Dead Enemy Tag | Tag identifying dead enemies (default: "Dead") |
Enable bShowDebug to see a colored sphere: Green = Calm, Red = Battle
Play different music for different enemy types. Boss music overrides elite, elite overrides regular.
| Priority | Level | Use Case |
|---|---|---|
| Boss | Highest | Boss fights, major encounters |
| Elite | Medium | Mini-bosses, elite enemies |
| Regular | Lowest | Standard enemies (uses default Battle Music) |
Check bUsePrioritySystem in component settings.
Add entries to EnemyPriorityConfigs array:
| Enemy Tag | Priority | Custom Music |
|---|---|---|
| "Boss" | Boss | BossMusic_Cue |
| "Elite" | Elite | EliteMusic_Cue |
| "Enemy" | Regular | None (uses Battle Music) |
EnemyEnemy + EliteEnemy + BossIf you're fighting 5 regular enemies and 1 boss enters, music immediately switches to boss music. When boss dies, returns to regular battle music.
Music volume scales dynamically based on how many enemies you're fighting.
| Intensity | Enemy Count | Default Volume |
|---|---|---|
| Low | 1-2 enemies | 60% |
| Medium | 3-5 enemies | 80% |
| High | 6+ enemies | 100% |
| Property | Default | Description |
|---|---|---|
| bUseIntensityModulation | false | Enable/disable feature |
| MinIntensityVolume | 0.6 | Volume at 1 enemy |
| MaxIntensityVolume | 1.0 | Volume at 6+ enemies |
Creates tension that builds as more enemies join the fight. A single enemy feels like a skirmish, a horde feels epic!
Begin music playback. Called automatically if bAutoStart is true.
Stop all music playback.
Immediately switch to battle music (ignores detection).
Immediately switch to calm music (ignores detection).
Change music volume. Useful for cutscenes or dialogue.
Reset OnFirstEnemyDetected event. Use when restarting level.
Fires when music state changes (Calm ↔ Battle).
Fires ONCE when first enemy is detected (per session).
Fires when intensity level changes (Low/Medium/High).
bUsePrioritySystem| Enum | Values |
|---|---|
| EMusicState | Calm, Battle, Fading |
| EEnemyPriority | Regular, Elite, Boss |
| EMusicIntensity | Low (1-2), Medium (3-5), High (6+) |
| Property | Type | Description |
|---|---|---|
| CurrentMusicState | EMusicState | Current state (Calm/Battle/Fading) |
| bMusicSystemActive | bool | Is music system running |
| DetectedEnemyCount | int32 | Number of enemies in range |
| CurrentEnemyPriority | EEnemyPriority | Highest priority enemy detected |
| CurrentIntensity | EMusicIntensity | Current intensity level |
| bEverDetectedEnemy | bool | Has any enemy ever been detected |
| Field | Type | Description |
|---|---|---|
| EnemyTag | FName | Tag to identify this enemy type |
| Priority | EEnemyPriority | Priority level (Regular/Elite/Boss) |
| CustomMusic | USoundBase* | Custom music for this priority (optional) |
bAutoStart enabled? Or did you call StartMusic()?InitialVolume)Enemy tag?DetectionRadius? (default 2000cm = 20m)bShowDebug to visualize detection sphereStateCooldown to prevent rapid switchingFadeTime for longer/shorter transitionsCheckInterval for detection frequencybUsePrioritySystem enabled?EnemyPriorityConfigs array configured?CustomMusic assigned in the priority config?bUseIntensityModulation enabled?MinIntensityVolume and MaxIntensityVolume valuesbShowDebug for visual feedbackDetectedEnemyCount in Details panel during play