bevy-ecs-systems
Skill16 starsChanged 3 months agoMITView on GitHub
Use when deriving `SystemParam`, grouping with `SystemSet`, gating execution with `.run_if(on_message::<M>())`/`in_state(...)`/`resource_exists::<R>`, ordering with `.before`/`.after`/`.chain()`, removing systems with `remove_systems_in_set`, or adapting resource bounds in Bevy 0.19.
In this repository33 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- bevy-a11ySkill
- bevy-animationSkill
- bevy-assetsSkill
- bevy-audioSkill
- bevy-camerasSkill
- bevy-captureSkill
- bevy-cargo-featuresSkill
- bevy-core-conceptsSkill
- bevy-custom-assetsSkill
- bevy-diagnostics-profilingSkill
- bevy-ecs-componentsSkill
- bevy-ecs-queriesSkill
- bevy-fluentSkill
- bevy-input-actionsSkill
- bevy-migration-0-17-to-0-18Skill
- bevy-migration-0-18-to-0-19Skill
- bevy-pbr-materialsSkill
- bevy-physicsSkill
- bevy-portingSkill
- bevy-renderingSkill
- bevy-save-loadSkill
- bevySkill
- bevy-testingSkill
- bevy-uiSkill
- bevy-vfxSkill
- bevy-voxel-dataSkill
- bevy-voxel-pipelineSkill
- bevy-voxel-runtimeSkill
- bevy-wasm-webgpuSkill
- similarity-rsSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 129
next_state.set(S)always firesOnExit/OnEnterin 0.18: Use set_if_neq for the old behaviour.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Bevy 0.19 — ECS Systems (params, sets, run conditions)
When to use this skill
- Bundling related state into a single system parameter via
#[derive(SystemParam)]. - Grouping systems into a
SystemSetso callers can order against the whole group. - Gating systems with run conditions (
run_if,on_message,in_state,resource_exists,any_with_component). - Hooking into state transitions with
OnEnter(S)/OnExit(S)/OnTransition { from, to }. - Hot-removing systems at runtime (e.g. tearing down a debug overlay) with
remove_systems_in_set. - Hitting
ScheduleBuildErrorambiguity panics — the executor no longer guesses.
Canonical pattern
use bevy::ecs::system::SystemParam;
use bevy::prelude::*;
#[derive(SystemSet, Hash, PartialEq, Eq, Clone, Debug)]
enum GameLoop { Input, Simulate, Render }
#[derive(States, Default, Hash, PartialEq, Eq, Clone, Debug)]
enum AppState { #[default] Loading, Playing }
#[derive(Resource, Default)]
struct Score(u32);
#[derive(Message)]
struct GoalScored { team: u8 }
// Composite param: pass one argument, get four.
// 'w = world borrow; 's = system-local state borrow.
#[derive(SystemParam)]
struct GameCtx<'w, 's> {
time: Res<'w, Time>,
score: ResMut<'w, Score>,
goals: MessageReader<'w, 's, GoalScored>,
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.init_resource::<Score>()
.add_message::<GoalScored>()
.init_state::<AppState>()
.configure_sets(Update, (GameLoop::Input, GameLoop::Simulate, GameLoop::Render).chain())
// State schedule: fires once when entering Playing.
.add_systems(OnEnter(AppState::Playing), spawn_level)
// State schedule: fires once when leaving Playing.
.add_systems(OnExit(AppState::Playing), despawn_level)
.add_systems(Update, read_input.in_set(GameLoop::Input))
.add_systems(
Update,
tally_goals
.in_set(GameLoop::Simulate)
.run_if(on_message::<GoalScored>),
)
.add_systems(Update, draw_hud.in_set(GameLoop::Render))
.run();
}
#[derive(Component)]
struct LevelEntity;
fn spawn_level(mut commands: Commands) {
commands.spawn((LevelEntity, Name::new("level")));
}
fn despawn_level(mut commands: Commands, query: Query<Entity, With<LevelEntity>>) {
for e in &query { commands.entity(e).despawn(); }
}
fn read_input(mut writer: MessageWriter<GoalScored>) {
writer.write(GoalScored { team: 0 });
}
fn tally_goals(mut ctx: GameCtx) {
let _ = ctx.time.delta_secs();
for goal in ctx.goals.read() {
ctx.score.0 += 1;
info!("team {} scored, total {}", goal.team, ctx.score.0);
}
}
fn draw_hud(score: Res<Score>) { let _ = score.0; }Run condition cheat sheet
| Built-in | Triggers when |
on_message::<M> | The Messages<M> buffer has unread items. |
resource_exists::<R> | Resource R is in the World. |
resource_changed::<R> | R was mutated this tick. |
in_state(MyState::X) | Current State<MyState> equals X. |
state_changed::<MyState> | The state changed this tick. |
any_with_component::<C> | At least one entity has C. |
Combine with .and() / .or(): run_if(in_state(GameState::Playing).and(resource_exists::<NetSession>())).
Topics
| Topic | Reference |
#[derive(SystemParam)], 'w/'s lifetimes, Local<T>, Commands deferred apply | references/system-params.md |
#[derive(SystemSet)] requirements, .in_set, .configure_sets, .chain() | references/system-sets.md |
Every built-in condition, .and()/.or()/not(), custom conditions, cost rule | references/run-conditions.md |
OnEnter(S) / OnExit(S) / OnTransition, NextState<S>, set_if_neq | references/state-schedules.md |
.before, .after, .chain(), .ambiguous_with, debugging ambiguity errors | references/ordering.md |
remove_systems_in_set, cleanup policies, cross-schedule runtime removal, side-effect limits | references/runtime-removal.md |
Bevy 0.19 gotchas
- Shared access does not define order. Conflicting mutable systems are serialized,
but their relative order is unspecified. Enable ambiguity diagnostics and add
.before,.after, or.chain()when behavior depends on order. See references/ordering.md. MessageReader/MessageWriter, notEventReader/EventWriter. Renamed in 0.17. Trait derive is#[derive(Message)]; registrar isapp.add_message::<M>().next_state.set(S)always firesOnExit/OnEnterin 0.18. Useset_if_neqfor the old behaviour. See references/state-schedules.md.- Do not remove the currently running schedule through
Schedules. It is temporarily absent from that resource. RemoveUpdatesystems from a later/different schedule such asLast. See references/runtime-removal.md. Resource: Componentin 0.19. Generic system parameters still useRes<T>/ResMut<T>, but aT: Resourcebound no longer proves thatTcannot appear in a component query.
See also
bevy-core-concepts— which schedule (Startup,Update,FixedUpdate) to add a system to.bevy-ecs-queries— query is one of manySystemParams;Changed<T>/Added<T>filters.bevy-ecs-components— defining theComponenttypes your systems act on.bevy-migration-0-17-to-0-18— full Message/Event rename,MaterialPluginchanges.bevy-migration-0-18-to-0-19— resource bounds and executor configuration.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

