GOAP
Goal Planning with GOAP
Plan action sequences from boolean facts, preconditions, effects, priorities, and costs.
- Audience
- AI designers and developers
- Time
- 20 minutes
- Requires
- A Flow Graph and boolean world-state facts
- Modules
- GOAP
On this page
Use GOAP when an agent should discover a sequence of actions that can transform current world facts into a desired goal state. You author goals and possible actions; the planner selects a valid, low-cost route at runtime.
Planning model
GoapRootowns the planner and its available children.GoapGoaldescribes desired boolean facts and priority.GoapActiondescribes preconditions, effects, execution work, and cost.- Blackboard booleans represent the facts the planner reads.
Lower goal priority numbers are evaluated first. Lower action cost makes a valid action more attractive within the plan.
Author a small planner
Create an agent that wants EnemyDefeated = true:
- Add
GoapRootand title itCombatPlanner. - Connect a normal Flow route to activate the root.
- Add
GoapGoaltitledDefeatEnemy. - Set its desired condition to
EnemyDefeated = true. - Add
GoapActiontitledMoveIntoRangewith the appropriate precondition and effectInRange = true. - Add
GoapActiontitledAttackwith preconditionInRange = trueand effectEnemyDefeated = true. - Set each Action’s Target Root Name to
CombatPlannerand connect it to the root’s child list. - Activate the goal through the supported GOAP goal instruction.
此处插图应该是 CombatPlanner GOAP 图的完整截图;显示 GoapRoot、DefeatEnemy Goal、MoveIntoRange 与 Attack Action,展开 Preconditions、Effects、Cost,并用箭头标出规划出的动作顺序。
Separate planned facts from real work
An action’s effects describe what becomes true when that action completes successfully. The action’s execution route must perform the real gameplay work: movement, animation, interaction, or combat.
Keep facts small and intentional. GOAP facts are boolean planning state, not a replacement for every numeric gameplay value. Derive facts such as InRange or HasAmmo from the systems that own those values.
Replanning
The planner checks preconditions as execution progresses. If relevant facts invalidate the active plan, it can replan from the new state. Use root status outputs such as Planned, Replanned, Goal Changed, and No Plan to expose decisions during authoring.
Common mistakes
- A Goal or Action is not connected to the root’s child list.
- Action Target Root Name does not match the root title.
- No goal is active.
- Two children under one root use ambiguous duplicate titles.
- A non-boolean value is used directly as a GOAP fact.
- Authored effects claim success before the gameplay action actually completes.
- Costs are tuned before the possible plans are verified.