ai-behavior-trees-utility-ai
它能做什么
该技能为两类游戏 AI 决策系统编写代码:行为树和效用评分。适合希望敌人或角色做出结构化、可信选择的游戏开发者。
适用场景
- ✓当你想为敌人或非玩家角色构建可复用的行为树时。
- ✓当你需要角色权衡多个选项,并为当下选出最佳选项时。
- ✓当你想调整敌人偏好某个行动胜过另一个行动的强度时。
技能链接
https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/disciplines/ai-behavior-trees-utility-ai/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我希望敌人用行为树来巡逻和追击,并用效用评分来选择使用哪种攻击。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会构建用于共享数据的黑板、行动与条件节点,以及序列和选择器等组合节点。它还会构建效用评估器,用响应曲线为每个行动评分,并可以将两者结合使用。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Behavior Trees & Utility AI
Two complementary ways to structure NPC decision-making, plus how to combine them. A behavior tree (BT) expresses structured, prioritized, reactive logic as a tree that is "ticked" each step. Utility AI answers "how much do I want each option right now?" by scoring actions with normalized curves and picking the best. Ship believable agents by using a BT for structure and Utility AI where graded trade-offs matter.
This skill is the implementation companion to game-ai (which helps you choose between
FSM / BT / steering / pathfinding). Read game-ai to pick a model; read this to build the
runtime.
When to use
- Use to build a reusable BT runtime: a
Blackboard,Nodebase, action/condition leaves,Sequence/Selector/Parallelcomposites, and decorators (Inverter, Cooldown, Repeat). - Use to build a Utility AI decider: response curves, considerations, and an evaluator that scores and selects actions (max, softmax, or weighted-random for variety).
- Use to build hybrid AI — a BT whose leaf delegates the "which attack / which target" choice to a utility evaluator.
When not to use: to choose between FSM, BT, steering, or pathfinding, and for A*/navmesh
routing, use game-ai. For Unreal's asset-based BehaviorTree/Blackboard, BTTask/BTService
and AIController, use unreal-behavior-trees. For the navmesh agent that moves the NPC, use
unity-navmesh or the engine's navigation node.
Core workflow
- Pick the model. Structured, prioritized, interruptible behavior → BT. Continuous "score every option" decisions (targeting, needs, item choice) → Utility. Both → hybrid.
- Design the Blackboard first. One typed key/value store per agent is the shared memory that decouples nodes; leaves read/write it and never hold references to each other.
- Write leaves. Conditions return
Success/Failureimmediately; actions returnRunningacross frames until they finish. Keep leaves small and side-effect-explicit. - Compose.
Selector= OR/fallback (first non-failure wins);Sequence= AND (stop at first non-success);Parallelfor concurrent branches. Wrap with decorators for policy (invert, cooldown, repeat, force-success). - For Utility: enumerate considerations, map each raw fact through a normalized 0..1 curve, combine (weighted product with compensation, or weighted sum), then select the max — add hysteresis so agents don't flip-flop on ties.
- Tick deliberately. Tick the tree/evaluator once per decision step (often slower than
render). Preserve
Runningstate between ticks; verify by drawing the active path and the per-action scores on screen while tuning.
Architecture at a glance
A behavior tree evaluates top-down, left-to-right; each node returns a status up to its parent:
flowchart TD
Root["Selector (root)"] --> Combat["Sequence: Combat"]
Root --> Patrol["Action: Patrol"]
Combat --> See["Condition: CanSeePlayer?"]
Combat --> InRange{"Selector: Reach"}
Combat --> Attack["Action: Attack (Running)"]
InRange --> Close["Condition: InAttackRange?"]
InRange --> MoveTo["Action: MoveToPlayer (Running)"]
Utility AI is a scoring pipeline — every candidate action is scored, then one is selected:
facts (distance, health, ammo…)
│ each fact → a normalized 0..1 response curve (consideration)
▼
score(action) = weight · combine(consideration_1 … consideration_n) # product+compensation or sum
▼
select: argmax · or softmax / weighted-random for variety · + hysteresis to avoid jitter
Status is a three-value enum shared by every node — this is the contract that makes the tree composable:
public enum Status { Success, Failure, Running }
public abstract class Node
{
public abstract Status Tick(Blackboard bb, float dt);
public virtual void Reset() { } // called when a parent abandons this subtree
}
// Selector = fallback/OR: return the first child that is not Failure.
// `Current` (from Composite) remembers a Running child so the next tick resumes there.
public sealed class Selector : Composite
{
public override Status Tick(Blackboard bb, float dt)
{
for (; Current < Children.Count; Current++)
{
var s = Children[Current].Tick(bb, dt);
if (s == Status.Running) return Status.Running;
常见问题
行为树和效用 AI 有什么区别?
行为树提供结构化、有优先级的步骤,而效用 AI 会为每个选项打分,从中选出最佳的一个。
我必须只选一种系统吗?
不必。该技能涵盖混合方案,即行为树在某些选择上调用效用评估器。
它适用于 Unreal 内置的行为树资源吗?
不适用。Unreal 基于资源的行为树由另一份 Unreal 技能涵盖。
详情
作者的原始描述
Build a production behavior-tree runtime (Blackboard, action/condition leaves, sequence/selector/parallel composites, decorators) and a Utility AI system (response curves — linear, exponential, sigmoid, quadratic — considerations, and action evaluators), plus hybrid BT-drives-Utility agents. Use when implementing a reusable behavior-tree or utility-based decision system, or tuning enemy/NPC decisions beyond a simple FSM, or when the user mentions behavior tree, blackboard, decorator, selector, sequence, tick status, utility AI, response/scoring curve, or consideration. For choosing between FSM
热度
- GitHub 星标
- 6.6k
- 排名
- #13791
- 许可证
- Apache-2.0
- 更新时间
- 2026/10/28
评论
- …