bevy-ecs-components
Skill16 starsChanged 3 months agoMITView on GitHub
Use when defining `#[derive(Component)]`, declaring required components with `#[require(...)]`, writing observers with `On<E>`, choosing Table versus SparseSet storage, registering `on_add`/`on_discard`/`on_remove` hooks, or migrating `Replace` lifecycle events 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-queriesSkill
- bevy-ecs-systemsSkill
- 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
4 rules. About 0 are common, 0 are distinctive, and 4 are 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.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 87
#[require(T)]runsT::default(): If T: !Default, use #[require(T = expression)] or #[require(T = T::new(...))]. - Very specific: line 88
Required components are recursive: If A requires B and B requires C, inserting A also inserts C.
- Very specific: line 89
ReplacebecameDiscardin 0.19: Use hooks on_add, on_insert, on_discard, and on_remove. - Very specific: line 90
Hooks: run inside World mutations, cannot take arbitrary SystemParams, and cannot despawn the entity they fire on.
≈ “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 Components
When to use this skill
- Defining a new
Componentfor game state. - Bundling components via
#[require(...)](the modern replacement for "bundles"). - Reacting to component lifecycle: spawning, despawning, inserting, removing.
- Observers — reacting to entity-targeted events with
On<E>. - Choosing storage: Table (default, fast iteration) vs SparseSet (fast add/remove).
Canonical pattern
use bevy::prelude::*;
// 1. Plain components.
#[derive(Component, Default)]
struct Health(f32);
#[derive(Component)]
struct Velocity(Vec3);
// 2. Required components — spawning `Player` auto-spawns the rest.
// `#[require]` accepts `Type` (Default), `Type(args)` (tuple constructor),
// or `Type = expression`.
#[derive(Component)]
#[require(Health = Health(100.0), Velocity = Velocity(Vec3::ZERO), Transform)]
struct Player;
// 3. Sparse storage for components added/removed every frame (e.g. tags
// flipped by gameplay). Default Table storage is faster to iterate.
#[derive(Component)]
#[component(storage = "SparseSet")]
struct Stunned;
// 4. An entity-targeted event reacted to by observers.
#[derive(EntityEvent)]
struct Damage {
entity: Entity, // EntityEvent requires an `entity` field.
amount: f32,
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, spawn_player)
.add_systems(Update, deal_damage)
.add_observer(on_damage)
.run();
}
fn spawn_player(mut commands: Commands) {
commands.spawn(Player);
}
fn deal_damage(mut commands: Commands, query: Query<Entity, With<Player>>) {
for entity in &query {
commands.trigger(Damage { entity, amount: 10.0 });
}
}
// Observer parameter is `On<E>`, not `Trigger<E>` (renamed in 0.17, PR #19596).
fn on_damage(damage: On<Damage>, mut query: Query<&mut Health>) {
let event = damage.event();
if let Ok(mut hp) = query.get_mut(event.entity) {
hp.0 -= event.amount;
}
}Bevy 0.19 gotchas
Trigger<E>is gone. Observer params areOn<E>in 0.17+. Methods:event(),event_mut(),observer(),original_event_target(),propagate(bool).EntityEvent::set_targetrequiresuse bevy::ecs::entity::SetEntityEventTarget;— not in the prelude.- Storage choice is irrevocable: it is compiled into the component. SparseSet is designed for frequent insertion/removal; Table is the default and usually iterates faster. Benchmark the real workload before changing storage.
#[require(T)]runsT::default(). IfT: !Default, use#[require(T = expression)]or#[require(T = T::new(...))].- Required components are recursive. If
ArequiresBandBrequiresC, insertingAalso insertsC. A constructor specified directly byAwins over an inherited constructor; requirement cycles are invalid. ReplacebecameDiscardin 0.19. Use hookson_add,on_insert,on_discard, andon_remove; the derive attribute is#[component(on_discard = path)].- Hooks run inside
Worldmutations, cannot take arbitrarySystemParams, and cannot despawn the entity they fire on. Use observers when you need flexibility. Resourceis now aComponentsubtrait. Do not derive both. Each resource value lives as a component on a resource entity, and inserting another value of the same resource type can move which entity owns the singleton; keep ordinary entity components and global resources as distinct types unless that behavior is intentional.Bundlederive still exists but most use-cases are better served by#[require(...)]on a "marker" component, which keeps the spawn surface ergonomic.
See also
bevy-ecs-queries— reading components back out.bevy-ecs-systems— observers are themselves systems.bevy-migration-0-17-to-0-18— fullTrigger→Onand event→message rename map.bevy-migration-0-18-to-0-19—Discardlifecycle events and resources-as-components.
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.

