A Behavior Tree is a mathematical model of plan execution used extensively in game development to create complex, lifelike AI. Unlike traditional Finite State Machines (FSMs), which become a "spaghetti" of transitions as complexity grows, BTs are inherently modular.
The tree functions through a Ticking system: the root sends a signal down the branches at regular intervals. Each node performs its logic and returns one of three statuses:
This structure allows for sophisticated decision-making. For instance, a "Combat" branch can be prioritized over a "Patrol" branch; if a "Decorator" node senses an enemy, it immediately interrupts lower-priority tasks to trigger an attack sequence. Because nodes are self-contained, developers can reuse the same "Find Path" or "Reload Weapon" logic across entirely different NPC types without rewriting code.