bevy-state-machines
БесплатноБез исполняемых скриптовНе проверенBevy ECS skill for app states and per-entity state data. Keywords: Bevy, States, NextState, OnEnter.
от thedivergentai★ 1 019 звёзд на GitHubОб этом скилле
Bevy state machines
When to use
Load this when the app needs a large-scale mode (paused, in a menu, loading) or when one entity needs a small mode flag. Use bevy::state for the first. Use a component for the second. Keep those two owners separate.
ECS shape
- App states.
bevy::state: states are app-wide finite state machines. Three types implementStates.- Standard states change only by setting the
NextState<S>resource. SubStatesalso useNextState<S>, and are removed from theWorldwhen source states are not in the required state.ComputedStatesderive from other states through acomputemethod.
- Standard states change only by setting the
- Transition schedules.
OnEnter<S>,OnExit<S>, andOnTransition<S>run systems on matching transitions.StateTransitionEvent<S>fires when stateSchanges. Run conditions:in_state<S>andstate_changed<S>. - Entity lifetime.
DespawnOnEnter<S>andDespawnOnExit<S>despawn entities on those transitions (state_scoped). - Feature.
bevy_stateships in the defaultbevyapp plugins. Install a state withinit_state. - Per-entity mode. Store an enum in a
Componentand branch in a system. That enum is not aStatestype.
[dependencies]
bevy = "0.20"
App modes are States. Gameplay systems use in_state. Pause writes NextState.
#[derive(States, Debug, Clone, Copy, Eq, PartialEq, Hash, Default)]
enum AppMode {
#[default]
Menu,
Play,
}
fn show_menu(mut commands: Commands) {
commands.spawn((Name::new("menu"), DespawnOnExit(AppMode::Menu)));
}
fn spawn_player(mut commands: Commands) {
commands.spawn((Name::new("player"), Transform::default()));
}
fn request_play(keys: Res<ButtonInput<KeyCode>>, mut next: ResMut<NextState<AppMode>>) {
if keys.just_pressed(KeyCode::Enter) {
next.set(AppMode::Play);
}
}
pub struct ModePlugin;
impl Plugin for ModePlugin {
fn build(&self, app: &mut App) {
app.init_state::<AppMode>()
.add_systems(OnEnter(AppMode::Menu), show_menu)
.add_systems(OnEnter(AppMode::Play), spawn_player)
.add_systems(Update, request_play.run_if(in_state(AppMode::Menu)));
}
}
A pause flag exists only while AppMode::Play is active. SubStates removes it otherwise.
#[derive(States, Debug, Clone, Copy, Eq, PartialEq, Hash, Default)]
enum AppMode {
#[default]
Menu,
Play,
}
#[derive(SubStates, Debug, Clone, Copy, Eq, PartialEq, Hash, Default)]
#[source(AppMode = AppMode::Play)]
enum Session {
#[default]
Running,
Paused,
}
fn toggle_pause(
keys: Res<ButtonInput<KeyCode>>,
session: Res<State<Session>>,
mut next: ResMut<NextState<Session>>,
) {
if keys.just_pressed(KeyCode::Escape) {
let flipped = match session.get() {
Session::Running => Session::Paused,
Session::Paused => Session::Running,
};
next.set(flipped);
}
}
fn install_pause(app: &mut App) {
app.add_sub_state::<Session>()
.add_systems(Update, toggle_pause.run_if(in_state(Session::Running)));
}
One actor's stance is a component. It does not change the app state.
#[derive(Component, Clone, Copy, PartialEq, Eq)]
enum Stance {
Idle,
Attack,
}
fn begin_attack(keys: Res<ButtonInput<KeyCode>>, mut actors: Query<&mut Stance>) {
if keys.just_pressed(KeyCode::KeyF) {
for mut stance in &mut actors {
*stance = Stance::Attack;
}
}
}
Choose the owner
| Need | Owner |
|---|---|
| App mode (menu, pause, play) | A States type and NextState<S> |
| Run logic only in one mode | in_state or an OnEnter / OnExit / OnTransition schedule |
| Child mode that exists only inside a parent mode | SubStates |
| Mode derived from other modes | ComputedStates |
| One actor's stance | An enum Component plus a system. Not States unless it is truly app-wide |
Scope
- Install app modes with
init_state. Install a child mode withadd_sub_state. OnEnter,OnExit, andin_statecover the schedules shown above.- A per-entity stance is the
Stancecomponent. Animation graphs belong on bevy-animation-graph.
Expert Knowledge Delta
Target: Bevy 0.20+.
Core ECS types: Component, Resource, Query, Commands, Startup, Update, Fixed / FixedMain (bevy::time), .chain(), Plugin, DefaultPlugins, MinimalPlugins. Messages and observers are an ownership slot. See bevy-events-messaging for their APIs. Systems run in parallel unless .chain() orders the ones that conflict.
Who owns state
| Piece | Owner | Who may mutate | Schedule |
|---|---|---|---|
| Data on one entity | Component |
One system via Query |
Update or FixedMain |
| One value for the whole app | Resource |
One system | Startup to insert, then the schedule that reads it |
| Spawn | Commands |
The spawning system | Startup for the initial world; later schedules for runt |
Установить bevy-state-machines в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл bevy-state-machines?
Bevy ECS skill for app states and per-entity state data. Keywords: Bevy, States, NextState, OnEnter.
Как установить скилл bevy-state-machines?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл bevy-state-machines запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic