# Drzewa zachowań

EN: **Behaviour trees** · id `behaviortrees` · aliases: behavior trees, behaviour trees, BT, drzewa zachowania, drzewo zachowań

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [AI w grach](https://aiatlasgraph.com/t/gameai.md) › [Zachowanie postaci w grach](https://aiatlasgraph.com/t/gamecharacters.md) › Drzewa zachowań

## Description

- PL: Hierarchiczna, modułowa struktura sterowania, w której węzły sekwencji, wyboru i akcji są cyklicznie odpytywane i zwracają sukces, porażkę lub stan w toku.
- EN: A hierarchical, modular control structure in which sequence, selector and action nodes are ticked periodically and return success, failure or running.

## In one sentence

- PL: Sposób zapisania, co postać ma robić, jako drzewko decyzji, które projektant może narysować, czytać i łatwo zmieniać.
- EN: A way to write down what a character should do as a decision tree that designers can draw, read and easily change.

## Problem it solves

- PL: Gdy postać ma dziesiątki zachowań, ręcznie połączone przejścia między nimi zamieniają się w plątaninę, której nikt nie umie poprawić.
- EN: When a character has dozens of behaviours, hand-wired transitions between them become a tangle nobody can fix.

## What it does

- PL: Jak przepis z wariantami: najpierw spróbuj tego, jeśli się nie uda, zrób tamto; każdą gałąź da się wymienić bez ruszania reszty.
- EN: Like a recipe with fallbacks: try this first, if it fails do that; any branch can be swapped without touching the rest.

## Everyday example

- PL: Pies w grze najpierw sprawdza, czy widzi gracza; jeśli tak, biegnie do niego, a jeśli nie, węszy po okolicy albo śpi.
- EN: A dog in a game first checks whether it sees the player; if so it runs over, if not it sniffs around or naps.

## This concerns you if you…

- PL: programujesz zachowanie postaci w silniku gry
- PL: sterujesz robotem i chcesz czytelnej logiki
- EN: script character behaviour in a game engine
- EN: control a robot and want readable logic

## Keywords

behavior trees · selector node · sequence node · blackboard · Unreal Engine Behavior Tree · BehaviorTree.CPP · py_trees · finite state machines

## How it works

- PL: Drzewo jest odpytywane od korzenia wiele razy na sekundę. Węzeł sekwencji wykonuje dzieci po kolei, dopóki się udają, a węzeł wyboru próbuje kolejnych, aż któreś zadziała. Liście sprawdzają warunki lub wykonują akcje. Dzięki ciągłemu odpytywaniu postać reaguje na zmiany, a poddrzewa można wielokrotnie używać.
- EN: The tree is ticked from the root many times per second. A sequence node runs children in order while they succeed, and a selector tries them in turn until one works. Leaves check conditions or perform actions. Constant ticking keeps the character reactive, and subtrees can be reused.

## Limits

- PL: Samo ręcznie zaprojektowane drzewo wykonuje zapisane zachowania i nie wyznacza nowych planów. Duże drzewa stają się trudne do ogarnięcia, a złożona koordynacja wielu postaci wymaga dodatkowych mechanizmów.
- EN: A hand-authored tree executes its specified behaviours and does not derive new plans by itself. Large trees become hard to manage, and complex coordination of many characters needs additional mechanisms.

## Key terms

- PL: **tick**: Jedno odpytanie drzewa, które decyduje o bieżącej akcji.
- PL: **selektor**: Węzeł próbujący kolejnych dzieci, aż któreś się powiedzie.
- PL: **sekwencja**: Węzeł wykonujący dzieci po kolei, dopóki każde się udaje.
- EN: **tick**: One evaluation pass deciding the current action.
- EN: **selector**: A node trying children in turn until one succeeds.
- EN: **sequence**: A node running children in order while each succeeds.

## Know first

- [Planowanie automatyczne (PDDL) (Automated planning (PDDL))](https://aiatlasgraph.com/t/classicalplanning.md)

## Related topics

Untyped, symmetric "see also" links.

- [Automaty stanów dla postaci (FSM) (Finite state machines for game characters)](https://aiatlasgraph.com/t/gamefsm.md)
- [Wybór działań przez punktację (utility AI) (Utility AI for game characters)](https://aiatlasgraph.com/t/utilityai.md)

## Sources

- [Behavior Trees in Robotics and AI: An Introduction](<https://arxiv.org/abs/1709.00084>) `colledanchise-ogren-bt-2017` · by Michele Colledanchise, Petter Ögren

---

AI Atlas revision 122 (2026-10-30) · HTML: https://aiatlasgraph.com/t/behaviortrees · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-10-30
