Beetmash
Docs > Beet > Guides > Behavior Trees

Behavior Trees

Behavior trees traditionally use a handful of simple primitives for control flow.

SequenceFlow

Run children in the order they were added and end if one fails. This example will run both children and return RunResult::Success

main.rs
world.spawn(SequenceFlow)
.with_children(|parent| {
parent.spawn(EndOnRun::success());
parent.spawn(EndOnRun::success());
})

FallbackFlow

Run children in the order they were added and end if one succeeds. This example will run both children and return RunResult::Success

main.rs
world.spawn(FallbackFlow)
.with_children(|parent| {
parent.spawn(EndOnRun::failure());
parent.spawn(EndOnRun::success());
})

ParallelFlow

This example will run both children and return RunResult::Success. Note that if both children return a RunResult this action will bubble both of them to its parent.

main.rs
world.spawn(ParallelFlow)
.with_children(|parent| {
parent.spawn_empty();
parent.spawn(EndOnRun::success());
})