Skip to content
crates · rust · bevy

Behavior trees forbevy_behavior

A game-agnostic behavior tree engine for Bevy with composable Selector / Sequence nodes, tick-based cooldown tracking, and observation traits so one tree can drive NPCs across many games.

Game-agnostic trees

BehaviorNode is generic over an Observation snapshot and an Action enum, so the same tree logic drives NPCs without game-specific coupling.

  • Used by — bevy_battle enemy turns, bevy_dungeon, and the mmorpg NPC brain.
  • Framework-free — pure Rust; Bevy is never required to evaluate a tree.
RustBevy crate
Framework-freeCore
ComposableNodes
MITLicense

What it gives you

Features

Generic tree

BehaviorNode is generic over an Observation type and an Action type, so each game supplies its own snapshot and command enum.

Composite nodes

Selector and Sequence compose leaves into trees.

Cooldown tracking

BehaviorContext, CooldownState, and TickCooldown gate actions by tick, per-NPC and globally.

Observation traits

Positioned, Healthed, Aware, and Ticked let built-in leaves query an NPC's world without knowing the concrete struct.

Built-in leaves

IsHealthLow, HasHostileNearby, Wander, Flee, AttackNearest, and CallAllies work on any observation that implements the traits.

Framework-free core

Pure Rust with serde as its only dependency, so trees run in a headless server or a non-Bevy host as easily as in an ECS.

Questions

Frequently asked

What is the bevy_behavior crate?

bevy_behavior is a game-agnostic behavior tree engine for Bevy. It provides the core BehaviorNode trait, Selector and Sequence composite nodes, a tick-based cooldown system, built-in leaves, and observation traits so the same tree logic can drive NPCs in different games.

How is a behavior tree parameterized?

The tree is generic over an Observation type (an immutable snapshot the NPC can see, implementing Positioned, Healthed, Aware, and Ticked) and an Action type (a game-defined command enum). A mutable BehaviorContext carries the current tick and cooldown handles per evaluation.

Does bevy_behavior require Bevy?

No. The crate is pure Rust with no framework dependency (serde only). An optional bevy feature exists, reserved for in-ECS integration, but the tree itself never needs it.

Discuss on the forum

Questions, fixes and notes on this page live in the KBVE forum.