
Leader Auras for AI Morale & Emotional Control in Unity
September 6, 2026Contextual Shouts bring NPCs to life by making them speak meaningful voice lines based on real in‑game events. This system is used in tactical games like Halo, Battlefield, The Last of Us, Squad to make AI communication feel smart and emotionally driven.
1. System Overview
The system has 4 core layers:
- Event Detector (e.g., enemy spotted, reload, taking fire)
- Shout Manager (checks cooldown, priority, suppression rules)
- Voice Database (ScriptableObject with audio + text + emotion tag)
- Playback Layer (AudioSource + optional subtitles)
This architecture avoids spam and ensures only meaningful, timed, filtered shouts occur.
2. Voice Line Data (ScriptableObject)
Create a flexible voice line object:
using UnityEngine;
public enum ShoutType
{
EnemySpotted,
TakingFire,
Reloading,
GrenadeThrown,
Flanking,
LowHealth,
LeaderDown,
Retreating,
Victory,
}
[CreateAssetMenu(menuName = "AI/Voice Line")]
public class VoiceLine : ScriptableObject
{
public ShoutType type;
public AudioClip[] clips;
public string subtitleText;
public float priority = 1f;
}
3. Voice Library (Per NPC Personality)
Each NPC has a personality-specific library:
using UnityEngine;
using System.Collections.Generic;
[CreateAssetMenu(menuName = "AI/Voice Library")]
public class VoiceLibrary : ScriptableObject
{
public List<VoiceLine> lines;
}
This allows:
- Brave NPCs → aggressive lines
- Scared NPCs → anxious lines
- Elite NPCs → professional, calm voice cues
4. Shout Manager
This prevents spam and handles priority rules.
using UnityEngine;
using System.Linq;
public class ShoutManager : MonoBehaviour
{
public VoiceLibrary library;
public AudioSource audioSource;
public float shoutCooldown = 1.5f;
private float shoutTimer = 0f;
private VoiceLine lastLine;
void Update()
{
if (shoutTimer > 0)
shoutTimer -= Time.deltaTime;
}
public void TryShout(ShoutType type)
{
if (shoutTimer > 0) return;
var candidates = library.lines.Where(l => l.type == type).ToList();
if (candidates.Count == 0) return;
// Pick highest priority
VoiceLine best = candidates.OrderByDescending(l => l.priority).First();
// Play random clip from that line
var clip = best.clips[Random.Range(0, best.clips.Length)];
audioSource.PlayOneShot(clip);
lastLine = best;
shoutTimer = shoutCooldown;
}
}
5. Event System
You can manually call shouts from AI logic, Behavior Trees, or sensors:
public class AIEvents : MonoBehaviour
{
private ShoutManager shouts;
void Start()
{
shouts = GetComponent<ShoutManager>();
}
public void OnEnemySpotted()
{
shouts.TryShout(ShoutType.EnemySpotted);
}
public void OnTakingFire()
{
shouts.TryShout(ShoutType.TakingFire);
}
public void OnReload()
{
shouts.TryShout(ShoutType.Reloading);
}
}
And you connect these to actual triggers:
- Vision system →
OnEnemySpotted - Health system →
OnTakingFire - Weapon system →
OnReload - Low HP monitor →
LowHealth
6. Cooldown + Priority Rules
We add smarter rules:
TakingFire → high priority Reloading → medium EnemySpotted → low LeaderDown → critical
We can prevent low-priority lines from interrupting important ones.
7. Group Shout Suppression (Prevent Echo Spam)
Only one NPC in a group should shout common events like:
- Enemy spotted
- Grenade thrown
- Fall back
We add a static suppression system:
public static class GroupShoutCooldown
{
private static float globalCooldown = 0f;
public static bool CanShout()
{
return Time.time > globalCooldown;
}
public static void Trigger(float duration)
{
globalCooldown = Time.time + duration;
}
}
Use it inside TryShout:
if (!GroupShoutCooldown.CanShout())
return;
GroupShoutCooldown.Trigger(1f);
8. Emotional Influence (Optional)
Tie voice cues to your emotional system:
- High fear → more shaky voice lines
- Low morale → panic lines appear
- High aggression → bold shouts
Add this filter before selecting a line:
if (emotion.fear > 0.7f)
type = ShoutType.Retreating;
9. Subtitles (Optional)
To show text for the voice clip:
public TMPro.TextMeshProUGUI subtitleUI;
IEnumerator ShowSubtitle(string text, float duration)
{
subtitleUI.text = text;
subtitleUI.enabled = true;
yield return new WaitForSeconds(duration);
subtitleUI.enabled = false;
}
10. Advanced Extensions
- Directional Shouts (“Left side!”, “Behind us!”)
- Player Cohesion Feedback (AI tells player what to do tactically)
- Radio Filter Layer (compressor + low bandpass for walkie-talkie NPCs)
- Squad Leader Commands (“Hold this point!”, “Suppress them!”)
- Who is listening? AI reacts to others’ shouts (shared knowledge)
Summary
With contextual voice cues, NPCs feel alive and intelligent, reacting to gameplay and communicating threats.
The system above supports:
- priority-based shout control
- personality-driven voice libraries
- group-level suppression
- emotion-linked voice variations
- dynamic combat-driven events
This is the same architecture used in AAA tactical games to create intense, realistic NPC communication.










