| Crates.io | bevy_fsm_macros |
| lib.rs | bevy_fsm_macros |
| version | 0.2.0 |
| created_at | 2025-10-25 15:07:14.464882+00 |
| updated_at | 2026-01-20 17:08:51.705695+00 |
| description | Procedural macros for bevy_fsm - FSM derive macros |
| homepage | |
| repository | https://github.com/ffmulks/bevy_fsm |
| max_upload_size | |
| id | 1900325 |
| size | 17,407 |
Procedural macros for bevy_fsm - an observer-driven finite state machine framework for Bevy ECS.
This crate provides two derive macros:
#[derive(FSMTransition)] - Generates a default "allow all" transition implementation#[derive(FSMState)] - Generates variant-specific event triggering infrastructureYou typically don't need to add this crate directly - it's re-exported by bevy_fsm.
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 | bevy_fsm_macros |
|---|---|
| 0.17 | 0.2 |
| 0.16 | 0.1 |
For complete documentation, examples, and best practices, see the main bevy_fsm crate.
Licensed under either of:
at your option.