--- name: bevy-app-resources description: "Bevy ECS skill for app-wide resources and schedules. Keywords: Bevy, Resource, App, Schedule, Plugin." --- # Bevy app resources ## When to use Load this when data or logic must exist for the whole app: one clock, one ruleset, startup spawn, or an ordered pair of systems. Pair with bevy-data-resources for the component-versus-resource split. ## ECS shape - **App.** The Apps page: an `App` contains a `World` and the outer loop. It initializes resources (one copy), adds systems to a `Schedule`, and imports other `App` changes through plugins. - **Resources.** `Resource`, `Res`, `ResMut`, and `insert_resource` (Resources page). `Time` arrives from `add_plugins(DefaultPlugins)`. - **Plugins.** The Resources page implements `Plugin` and inserts the resource inside `build`. `DefaultPlugins` is the plugin set that adds `Time`. Name only the plugins this page documents. - **Schedules.** `add_systems(Startup, ...)` runs once before other systems. `add_systems(Update, ...)` is the repeating schedule in the ECS page. `.chain()` orders systems that must see each other's writes. `bevy::ecs::message` names `FixedUpdate` only as the schedule after which `signal_message_update_system` runs. Fixed-timestep clock types stay in bevy-character-movement. - **States.** App-wide modes are `bevy::state`, not a global node. See bevy-state-machines. ## App choices | Need | Bevy idiom | | --- | --- | | One copy for the whole app | A `Resource` inserted on the `App` | | Logic that ticks every frame | A system on `Update` (or a chained pair) | | Boot setup | A `Startup` system or `insert_resource` in a `Plugin` | | One-shot notice | A message or event. See bevy-events-messaging. | ## Scope - Insert app-wide data with `insert_resource` inside `Plugin::build`, or from a `Startup` system. - Order two systems that both mutably use the same resource with `.chain()`. - Save files are a `Resource` you serialize yourself. The running copy stays in the `World`. ## Examples ```toml [package] name = "app_resources" version = "0.1.0" edition = "2021" [dependencies] bevy = "0.20" ``` One rules resource, one startup spawn, and a pair of systems that must not race on `Score`. ```rust #[derive(Resource)] struct Ruleset { gravity: f32, } #[derive(Resource, Default)] struct Score(u32); #[derive(Component)] struct Falling; fn spawn_session(mut commands: Commands) { commands.spawn((Name::new("session"), Transform::default(), Falling)); } fn apply_gravity( rules: Res, time: Res