HTN Planner AI decision making
Dawn Engine HTN Planner is a hierarchical task network (HTN) AI planning system: you author task-decomposition knowledge as a Domain, the planner solves a Plan against the agent’s WorldState, and HtnAgentComponent executes that plan with automatic replan on failure or environment change. Decisions are deterministic, explainable, and replayable.
Maturity: shipped. Provided by the HtnPlanner Gem (Code Gem; no hard Gem dependencies). After enablement, HtnSystemComponent mounts automatically; you still add HtnAgentComponent on AI entities and assign a compiled Domain asset.
It does not replace animation, navigation, or combat systems: operators call those capabilities. It also does not replicate WorldState over the network—authority usually owns the agent and runs planning locally.
What problem it solves
Game AI and simulation agents need goal-driven behavior that stays readable as tactics grow. Hand-rolled state machines and opaque ML policies become hard to explain (“why did it do that?”) and hard to author with designers. HTN Planner provides:
- A Domain graph of compound tasks, methods, and primitive operators;
- Deterministic planning (same Domain + same WorldState → byte-identical Plan);
- Per-entity plan execution with continuous mode, opportunistic replan, and failure backoff;
- Three extension channels (C++ operators,
.htnnodepresets/macros, script operators) without forking the Gem; - HTN Canvas (standalone node editor), compile-time V1–V18 validation, ImGui live panel, and offline decomposition-trace replay.
With the Gem disabled, projects have no HTN planning path; O3DE itself ships no AI decision framework.
How it works
.htndomain (HTN Canvas graph)
│
▼
AssetProcessor / HtnDomainBuilder ──► .htndomain_compiled (flat HtnDomainAsset)
│
sensors / game code / scripts ──► WorldState │
▼
HtnAgentComponent → FindPlan (DFS) → HtnPlanRunner
│
▼
IHtnOperator Begin/Tick → nav / anim / script / …
Two rules run through the Gem:
- Model vs view: Domain data never depends on Qt/GraphCanvas; the editor graph is an authoring view; the builder flattens it to a read-only runtime asset shared by agents.
- Extend via data/reflection: new tasks and operators register through C++,
.htnnodeJSON, or BehaviorContext—do not fork HtnPlanner for gameplay content.
Planning runs on a WorldState snapshot; effects are simulated during search, then committed at runtime by phase (PlanOnly / ApplyOnStart / ApplyOnSuccess). Decomposition is time-sliced across agents under a global per-frame step budget; results match one-shot FindPlan byte-for-byte.
In this section
| Chapter | Contents |
|---|---|
| Getting started | Enable the Gem, add HTN Agent, run the guard sample end to end, verify it works |
| Core concepts | WorldState, Task, Method, Condition, Effect phases, Plan, MTR, and the planning→execution data flow |
| HTN Agent component | All configuration fields, the Idle/Planning/Executing/Failed state machine, request and notification buses, Domain hot reload |
| WorldState and scripting | The eight HtnValue types, C++ and Lua/ScriptCanvas read/write, script value boxing pitfalls, script operator completion tokens |
| Authoring Domains | HTN Canvas workflow, source vs compiled assets, Domain Import, .htnnode files, V1–V18 validation rules |
| Extending operators | The three extension channels with copyable examples, built-in operator reference, predicate contract |
| Debugging | Console commands, ImGui live panel, offline trace replay in Canvas, global statistics |
| Reference | Settings Registry keys, capability limits, troubleshooting, programmatic API overview |
Related capabilities
- Navigation3D HTN integration: optional
Nav3D.*operators when both Gems are enabled;HtnPlanneritself has no hard dependency on it. - Dawn Stream: remotely review levels that include HTN-driven agents.
Getting started
Enable the HtnPlanner Gem, run your first HTN agent with the guard sample Domain, and verify planning works.
Core concepts
Understand WorldState, Task, Method, Condition, Effect phases, Plan, and MTR, plus the full planning-to-execution data flow.
HTN Agent component
All HtnAgentComponent configuration fields, run-control APIs, event notifications, and the Idle/Planning/Executing/Failed state machine.
WorldState and scripting
The eight HtnValue types, reading and writing WorldState from C++ and Lua/ScriptCanvas, script value-boxing pitfalls, and script operator completion callbacks.
Authoring Domains
Edit Domains visually with HTN Canvas, understand source vs compiled assets, cross-domain imports, .htnnode extension assets, and the V1–V18 validation rules.
Extending operators
Add custom operators and predicates via C++ registration, .htnnode JSON presets/macros, and script operators, with a built-in operator reference.
Debugging
Locate planning issues with console commands, the ImGui live panel, and offline trace replay in HTN Canvas; interpret global statistics.
Reference
Settings Registry keys, capability limits, the troubleshooting table, and a programmatic API overview.