本文へスキップ
Skillpedia
一般的なプログラミング6.6k · #13791

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に貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/disciplines/ai-behavior-trees-utility-ai/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

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, Node base, action/condition leaves, Sequence/Selector/Parallel composites, 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

  1. Pick the model. Structured, prioritized, interruptible behavior → BT. Continuous "score every option" decisions (targeting, needs, item choice) → Utility. Both → hybrid.
  2. 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.
  3. Write leaves. Conditions return Success/Failure immediately; actions return Running across frames until they finish. Keep leaves small and side-effect-explicit.
  4. Compose. Selector = OR/fallback (first non-failure wins); Sequence = AND (stop at first non-success); Parallel for concurrent branches. Wrap with decorators for policy (invert, cooldown, repeat, force-success).
  5. 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.
  6. Tick deliberately. Tick the tree/evaluator once per decision step (often slower than render). Preserve Running state 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

repo: gamedev-skills/awesome-gamedev-agent-skills

人気

GitHubのスター
6.6k
ランキング
#13791
ライセンス
Apache-2.0
更新日
2026/10/28

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル