AI in Unreal Engine Best Practices
Production-quality AI in Unreal requires profiling, debugging tools, smart architecture decisions, and awareness of multiplayer and platform constraints.
Performance Profiling
- Unreal Insights: Use the built-in profiler to measure AI tick times, navigation queries, perception updates, and EQS query costs.
- AI Debug Visualizations: Press the apostrophe key (') to cycle through AI debug views: NavMesh, BT state, EQS results, perception.
- Stat commands: Use
stat AI,stat Navigation, andstat Gameto monitor AI performance in real-time. - Budget targets: Keep total AI cost under 4ms for 30+ agents at 60fps. Profile on target hardware, not just your development PC.
Debugging Tools
Gameplay Debugger
Press apostrophe (') to open the Gameplay Debugger. Select an AI agent to see its behavior tree state, blackboard values, perception info, and active EQS queries.
Visual Logger
Window → Developer Tools → Visual Logger. Records AI decisions over time with snapshots. Scrub through the timeline to understand exactly what happened and when.
BT Debugger
The Behavior Tree editor shows live execution state when running PIE. Active nodes glow green, and you can inspect blackboard values in real-time.
EQS Testing Pawn
Place an EQS Testing Pawn in the level to visualize query results as colored spheres in the viewport without running the game.
Architecture Recommendations
| Practice | Description |
|---|---|
| C++ base, BP config | Write AI systems in C++, expose parameters to Blueprint for designer tuning |
| Shared BT subtrees | Create reusable subtrees for common patterns (patrol, combat, flee) shared across enemy types |
| Blackboard inheritance | Use parent blackboards for shared keys and child blackboards for type-specific data |
| Service-based updates | Use BT Services for periodic calculations instead of Tick. Configure intervals per service. |
| EQS caching | Cache EQS query results and only re-run when context changes significantly |
Multiplayer AI
- Server authority: Run all AI logic on the server. Replicate movement and state to clients.
- Relevancy: Use net relevancy to avoid replicating distant AI to clients who cannot see them.
- Dormancy: Mark distant AI actors as dormant to reduce network bandwidth.
- Prediction: Interpolate AI movement on clients for smooth visual results despite network latency.
With traditional actors and full behavior trees: 50-100 agents comfortably. With Mass Entity and LOD: thousands. The key is using the right system for each tier. Important enemies get full actors; background crowds use Mass Entity with simplified processing.
Behavior Trees are the mature, well-documented choice for individual important NPCs. State Trees are designed for Mass Entity and lightweight, data-driven decision-making at scale. Use BTs for your main cast and State Trees for crowd agents.
Lilly Tech Systems