Aller au contenu
Skillpedia
Programmation générale6.6k · #13852

unreal-behavior-trees

Ce qu’il fait

Explique comment configurer l'IA des personnages non joueurs dans Unreal Engine 5 à l'aide des arbres de comportement. Elle s'adresse aux développeurs qui créent des ennemis ou d'autres personnages qui font des choix.

Quand l’utiliser

  • ✓Quand vous construisez un ennemi ou un PNJ qui doit choisir ses actions dans Unreal Engine 5.
  • ✓Quand vous devez ajouter des conditions ou des vérifications périodiques à une structure de décision d'IA.
  • ✓Quand vous voulez écrire des nœuds de comportement personnalisés ou relier un contrôleur d'IA à un arbre de comportement.

Lien du skill

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unreal/unreal-behavior-trees/SKILL.md

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unreal/unreal-behavior-trees/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Fais patrouiller mon ennemi Unreal jusqu'à ce qu'il voie le joueur, puis fais-le le poursuivre.”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

Elle explique comment organiser l'arbre avec des sélecteurs et des séquences, ajouter des conditions et des mises à jour en arrière-plan, et lancer l'arbre depuis un contrôleur d'IA qui utilise un Blackboard pour les informations partagées.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis GitHub.

Unreal Behavior Trees

Author NPC decision-making in UE5 with Behavior Trees driven by a Blackboard: structure the tree with composites, gate branches with decorators, keep state current with services, and run it from an AIController. Targets UE 5.8.

When to use

  • Use when building enemy/NPC AI: creating a BT_/BB_ asset pair, structuring Selector/Sequence branches, adding decorators (conditions) and services (periodic updates), writing custom BTTask/BTService nodes, or wiring an AIController to run the tree.
  • Use when the project has Behavior Tree (BT_) and Blackboard (BB_) assets and an AAIController.

When not to use: the concept of AI (FSM vs BT vs steering, cross-engine) → game-ai. Pure navigation/pathing math is engine navmesh (BT's MoveTo uses it). Simple one-off logic may be cheaper as a small state machine than a full tree.

Behavior Tree or StateTree? UE 5.8 ships both, and Behavior Trees are not deprecated. StateTree is Epic's general-purpose hierarchical state machine: it combines BT-style selection with explicit States and Transitions. If the project already uses StateTree assets, or the AI is naturally a set of modes with clear transitions (patrol → alert → combat), check with the user before adding a Behavior Tree next to it. Keep using Behavior Trees where the project already has BT_/BB_ assets.

Core workflow

  1. Create the pair: a Blackboard (BB_) holds typed keys (the AI's memory: TargetActor, LastKnownLocation, bIsInvestigating); a Behavior Tree (BT_) references that Blackboard.
  2. Possess and run. An AAIController possesses the pawn and calls RunBehaviorTree(BT), which also initializes the referenced Blackboard.
  3. Structure with composites. Selector runs children left→right until one succeeds (priority/fallback: "attack, else chase, else patrol"). Sequence runs children until one fails (do-all: "move to cover → reload → peek"). Simple Parallel runs one main task alongside a secondary.
  4. Gate branches with Decorators that read Blackboard keys (e.g. "Has Target?" guards the combat branch). Set Observer Aborts so the tree re-evaluates when the key changes.
  5. Keep the Blackboard current with Services attached to a branch — they tick periodically (e.g. update TargetActor via a sight check) only while that branch is active.
  6. Do work in Tasks, which return Succeeded, Failed, or InProgress (latent tasks like MoveTo finish later).
  7. Verify with the Behavior Tree debugger during PIE — it highlights the running node and shows live Blackboard values, so you see exactly which branch executes.

Patterns

1. AIController that runs the tree (C++)

void AEnemyAIController::OnPossess(APawn* InPawn)
{
    Super::OnPossess(InPawn);
    if (BehaviorTree)                 // UPROPERTY(EditAnywhere) TObjectPtr<UBehaviorTree>
        RunBehaviorTree(BehaviorTree); // initializes & uses the Blackboard the BT references
}

2. A priority tree (node structure)

ROOT
└── Selector (try combat, else investigate, else patrol)
    ├── Sequence            [Decorator: Blackboard 'TargetActor' Is Set, Observer Aborts: Both]
    │     ├── Task: MoveTo (TargetActor)          // latent: returns InProgress then Succeeded
    │     └── Task: Attack
    ├── Sequence            [Decorator: 'LastKnownLocation' Is Set]
    │     ├── Task: MoveTo (LastKnownLocation)
    │     └── Task: Wait (3s) + clear key
    └── Task: Patrol (BTTask_FindPatrolPoint -> MoveTo)

Observer Aborts: Both makes the combat branch interrupt patrol the instant TargetActor is set, and bail out when it's cleared — this is what makes the AI feel reactive.

3. Updating the Blackboard from code (e.g. on seeing the player)

void AEnemyAIController::SetTarget(AActor* Target)
{
    if (UBlackboardComponent* BB = GetBlackboardComponent())
        BB->SetValueAsObject(TEXT("TargetActor"), Target);   // key name must match the BB asset
}
// Clear with BB->ClearValue(TEXT("TargetActor")); to drop back to a lower-priority branch.

Pitfalls

  • AI never starts — the pawn isn't possessed (set the Pawn's Auto Possess AI to "Placed in World or Spawned" and assign the AIController), or RunBehaviorTree was never called.
  • MoveTo instantly fails — no NavMesh in the level (add a Nav Mesh Bounds Volume), or the target is off the navmesh.
  • **Branch doesn't rea
Questions fréquentes

Qu'est-ce qu'un Blackboard ?

Un Blackboard est un espace partagé d'informations, comme la position du joueur, que l'arbre de comportement lit.

Dois-je utiliser StateTree à la place ?

La compétence indique de demander d'abord à l'utilisateur, car les deux systèmes existent dans Unreal Engine 5.8 et un projet peut déjà en utiliser un.

Couvre-t-elle les calculs de chemin ?

Pas en profondeur. Le mouvement utilise le système de navigation du moteur, qui est un sujet distinct.

Détails

Description originale de l’auteur

Build NPC AI in Unreal Engine 5 with Behavior Trees and Blackboards: composites (Selector/Sequence), tasks, decorators, services, and running the tree from an AIController. Use when creating enemy/NPC AI, BT_/BB_ assets, custom BTTask or BTService nodes, or when the user mentions Behavior Tree, Blackboard, AIController, BTTask, decorator, or service.

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

Popularité

Étoiles GitHub
6.6k
Position au classement
#13852
Licence
Apache-2.0
Mis à jour
28/10/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires