rusteventsbevy

Bevy system could not access system parameter ResMut<Events<event>>


I am trying to learn Bevy but I run into a weird issue. When I try to insert a custom event into a system variables, the game crashes at start.

The code:

[package]
name = "bevy_playground"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy = "0.15.3"
use bevy::prelude::*;

fn main() {
    let mut app = App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Update, dummy)
        .run();
}

#[derive(Event)]
struct Score;

fn dummy(mut events: EventWriter<Score>) {
    // ...
}

error:

dummy could not access system parameter ResMut<Events<Score>>

Am I perhaps missing some detail? What am I doing wrong?

full output:

2025-03-05T16:31:03.441833Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 11 Home", kernel: "26100", cpu: "", core_count: "12", memory: "31.6 GiB" }
2025-03-05T16:31:03.643666Z  INFO bevy_render::renderer: AdapterInfo { name: "Qualcomm(R) Adreno(TM) X1-85 GPU", vendor: 20803, device: 909329200, device_type: Integrat
edGpu, driver: "Qualcomm Technologies Inc. Adreno Vulkan Driver", driver_info: "Driver Build: , , 1698055923\nDate: 10/23/2023\nCompiler Version: E031.47.15.00\nDriver Branch: \n", backend: Vulkan }
2025-03-05T16:31:04.249683Z  INFO bevy_winit::system: Creating new window "App" (0v1#4294967296)
thread 'main' panicked at C:\Users\fanda\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_ecs-0.15.3\src\system\function_system.rs:216:28:
bevy_playground::dummy could not access system parameter ResMut<Events<Score>>
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!

Solution

  • Ok, so it turns out that I didn't add the event to the app:

    .add_event::<Score>()
    

    Note for devs: You should deffinitely add this to the event docs: https://docs.rs/bevy/latest/bevy/ecs/event/struct.EventWriter.html