Fyrox AI

State machines and behavior trees for game AI in Rust. Composable, serializable, engine-agnostic. Free core (MIT) with a Pro visual editor for FyroxEd.

Rust 1.87+ MIT (Free) serde + nalgebra Fyrox-agnostic

Architecture Overview

State Machine States + Transitions
Blackboard Shared Variables
Behavior Tree 9 Node Types

The Blackboard acts as shared memory between the State Machine and Behavior Tree. Transitions and BT conditions read from the blackboard; actions write back to it. This decoupled architecture lets you mix high-level state control with detailed behavior logic.

Free Features MIT

The core library is engine-agnostic, MIT-licensed, and depends only on serde and nalgebra. Use it in any Rust project.

🔄 State Machine

Define states with named transitions. Each transition evaluates conditions against the blackboard to decide when to switch. Supports guard conditions and fallback states.

🌳 Behavior Tree (9 Nodes)

Sequence, Selector, Parallel, Inverter, Repeater, Succeeder, Failer, Delay, and Action. Compose complex decision-making from simple building blocks.

📋 Blackboard (5 Types)

Shared key-value store with Bool, Int, Float, String, and Vec3. Both state machines and behavior trees read and write the same blackboard instance.

🧮 Condition Logic

Composable And, Or, and Not operators for transition guards and BT conditions. Build arbitrarily complex conditions from simple comparisons.

💾 Full Serde Support

Every type implements Serialize and Deserialize. Save AI configurations to JSON, RON, or any serde-compatible format. Hot-reload friendly.

🔌 Engine-Agnostic

No Fyrox dependency in the core crate. Only serde + nalgebra. Use with Fyrox, Bevy, macroquad, or pure Rust servers and simulations.

Pro Features Paid

Visual editor integration for FyroxEd. Design AI visually, inspect at runtime, debug with full history.

🎨 Visual State Graph Editor

3-panel layout: blackboard panel on the left, graph canvas in the center for drag-and-drop state and transition design, state details on the right for configuring conditions.

🔍 Blackboard Inspector

Live panel showing all blackboard keys, types, and current values. Edit values at runtime for rapid testing and debugging of AI behavior.

📊 AiDebugLogger

Logs every state transition with timestamps. Review transition history to understand why AI made specific decisions. Filter by entity or state name.

PriorityStateMachine

Extended state machine where states have priority levels. Higher-priority states can interrupt lower-priority ones, ideal for alert/combat AI patterns.

↩️ Full Undo/Redo

All editor operations go through the Fyrox command system. Every graph edit, connection change, and property modification can be undone and redone.

🧩 Editor Integration

Runs natively inside FyroxEd as a plugin. No external tools needed. AI graphs are saved as part of your Fyrox project and version-controlled normally.

Quick Start

A basic state machine with Idle, Patrol, and Chase states. The blackboard drives transitions.

use fyrox_ai::{StateMachine, State, Transition, Blackboard, Condition};
use fyrox_ai::BlackboardValue::{Bool, Float};

// Create a shared blackboard
let mut bb = Blackboard::new();
bb.set("player_visible", Bool(false));
bb.set("patrol_timer",   Float(0.0));

// Define states
let idle   = State::new("Idle");
let patrol = State::new("Patrol");
let chase  = State::new("Chase");

// Build the state machine
let mut sm = StateMachine::builder()
    .state(idle)
    .state(patrol)
    .state(chase)
    .transition(
        Transition::new("Idle", "Patrol")
            .condition(Condition::gte("patrol_timer", Float(3.0)))
    )
    .transition(
        Transition::new("Patrol", "Chase")
            .condition(Condition::eq("player_visible", Bool(true)))
    )
    .transition(
        Transition::new("Chase", "Idle")
            .condition(Condition::eq("player_visible", Bool(false)))
    )
    .initial("Idle")
    .build();

// Tick each frame
sm.update(&bb);
println!("Current state: {}", sm.current().name());

Free vs Pro

The free core covers everything you need at runtime. Pro adds visual tooling and advanced features.

Feature Free (MIT) Pro
State Machine with transitions
Behavior Tree (9 node types)
Blackboard (5 value types)
Condition logic (And/Or/Not)
Full serde serialization
Engine-agnostic (serde + nalgebra only)
Visual State Graph Editor
3-Panel Layout (blackboard, canvas, details)
Blackboard Inspector Panel
AiDebugLogger (transition history)
PriorityStateMachine
Full undo/redo in editor

Frequently Asked Questions

What is Fyrox AI?

Fyrox AI is a Rust library for building game AI using state machines and behavior trees. It provides a composable state machine with transitions, 9 behavior tree node types (Sequence, Selector, Parallel, Inverter, Repeater, Succeeder, Failer, Delay, Action), a shared blackboard with 5 value types (Bool, Int, Float, String, Vec3), and composable condition logic (And/Or/Not). The free version is MIT-licensed and engine-agnostic.

Do I need the Fyrox engine to use it?

No. The free core library depends only on serde and nalgebra, so you can use it in any Rust project — with Fyrox, Bevy, macroquad, or even a headless server. The Pro visual editor requires FyroxEd, but the core AI logic works anywhere.

How does the Pro visual editor work?

Fyrox AI Pro adds a 3-panel visual editor inside FyroxEd: a blackboard panel on the left for inspecting variables, a graph canvas in the center for designing state machines with drag-and-drop, and a state details panel on the right for configuring transitions and conditions. All changes support full undo/redo.

Can I use Fyrox AI with fyrox-dialog?

Yes. Both systems use a blackboard for condition evaluation, so they can share game state. An NPC's AI state machine can check dialog flags, and dialog condition nodes can read AI state variables. This lets you build NPCs that change behavior based on conversation outcomes.

What is the difference between a State Machine and a Behavior Tree?

A state machine defines distinct states (Idle, Patrol, Chase) with explicit transitions based on conditions. A behavior tree organizes behaviors as a tree evaluated top-down, with nodes like Sequence, Selector, and Parallel for complex decision-making. Fyrox AI provides both — use a state machine for high-level modes and behavior trees within each state for detailed logic.

Build smarter game AI, faster

Start free with the MIT-licensed core. Add the Pro visual editor when you need it.