bevy_fsm_macros

Crates.iobevy_fsm_macros
lib.rsbevy_fsm_macros
version0.2.0
created_at2025-10-25 15:07:14.464882+00
updated_at2026-01-20 17:08:51.705695+00
descriptionProcedural macros for bevy_fsm - FSM derive macros
homepage
repositoryhttps://github.com/ffmulks/bevy_fsm
max_upload_size
id1900325
size17,407
Florian Mulks (ffmulks)

documentation

README

bevy_fsm_macros

Procedural macros for bevy_fsm - an observer-driven finite state machine framework for Bevy ECS.

What This Crate Provides

This crate provides two derive macros:

  • #[derive(FSMTransition)] - Generates a default "allow all" transition implementation
  • #[derive(FSMState)] - Generates variant-specific event triggering infrastructure

You typically don't need to add this crate directly - it's re-exported by bevy_fsm.

Usage

use bevy::prelude::*;
use bevy_fsm::{FSMState, FSMTransition, FSMPlugin};
use bevy_enum_event::EnumEvent;

// Zero boilerplate - FSMTransition derive allows all transitions
#[derive(Component, EnumEvent, FSMTransition, FSMState, Reflect, Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[reflect(Component)]
enum GameState {
    MainMenu,
    Playing,
    GameOver,
}

fn setup(app: &mut App) {
    app.add_plugins(FSMPlugin::<GameState>::default());
}

For custom transition rules, skip the FSMTransition derive and implement the trait manually:

use bevy_fsm::FSMTransition;

#[derive(Component, EnumEvent, FSMState, Reflect, Clone, Copy, Debug, PartialEq, Eq, Hash)]
enum LifeFSM {
    Alive,
    Dying,
    Dead,
}

impl FSMTransition for LifeFSM {
    fn can_transition(from: Self, to: Self) -> bool {
        matches!((from, to),
            (LifeFSM::Alive, LifeFSM::Dying) |
            (LifeFSM::Dying, LifeFSM::Dead)) || from == to
    }
}

Bevy Compatibility

Bevy bevy_fsm_macros
0.17 0.2
0.16 0.1

Documentation

For complete documentation, examples, and best practices, see the main bevy_fsm crate.

License

Licensed under either of:

at your option.

Commit count: 16

cargo fmt