Skip to content

"Entity does not exist" warning triggered by DespawnOnExitState for all child components #19777

Open
@will-hart

Description

@will-hart

Bevy version

bevy = { git = "https://github.com/bevyengine/bevy", branch = "main" } (commit c6ae964)

What you did

Created a basic application that spawns an entity + child and immediately switches state.

What went wrong

  • 0.16.0 no warning in logs
  • Warning in logs about trying to despawn an entity that was already despawned.

Additional information

This is a minor annoyance for a minimal example, but makes logs very noisy when running with anything beyond a simple application e.g. a minimal bevy_new_2d app with the demo app deleted emits about 15 warnings to get to the gameplay state.

Related discussion #5617

Minimal repro
use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .init_state::<AppState>() // Alternatively we could use .insert_state(AppState::Menu)
        .add_systems(Startup, setup)
        .add_systems(OnEnter(AppState::Menu), change_state)
        .run();
}

#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
enum AppState {
    #[default]
    Menu,
    InGame,
}

fn setup(mut commands: Commands) {
    commands.spawn((
        Name::new("ME"),
        DespawnOnExitState(AppState::Menu),
        // StateScoped(AppState::Menu),
        children![Name::new("MY KID")],
    ));
}

fn change_state(mut next_state: ResMut<NextState<AppState>>) {
    info!("Going to game state");
    next_state.set(AppState::InGame);
}
Log With `0.16.1`
~/src/bevytest   main  cargo run
   Compiling bevytest v0.1.0 (/Users/will/src/bevytest)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.21s
     Running `target/debug/bevytest`
2025-06-22T06:05:34.794353Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "macOS 15.5 Sequoia", kernel: "24.5.0", cpu: "Apple M1", core_count: "8", memory: "8.0 GiB" }
2025-06-22T06:05:34.896192Z  INFO bevy_render::renderer: AdapterInfo { name: "Apple M1", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }
2025-06-22T06:05:35.403381Z  INFO bevy_render::batching::gpu_preprocessing: GPU preprocessing is fully supported on this device.
2025-06-22T06:05:35.441436Z  INFO bevy_winit::system: Creating new window App (0v1)
2025-06-22T06:05:37.125189Z  INFO bevytest: Going to game state

With c6ae964:

 ~/src/bevytest   main  cargo run
   Compiling bevytest v0.1.0 (/Users/will/src/bevytest)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.84s
     Running `target/debug/bevytest`
2025-06-22T06:11:17.177839Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "macOS 15.5 Sequoia", kernel: "24.5.0", cpu: "Apple M1", core_count: "8", memory: "8.0 GiB" }
2025-06-22T06:11:17.278648Z  INFO bevy_render::renderer: AdapterInfo { name: "Apple M1", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }
2025-06-22T06:11:17.630157Z  INFO bevy_render::batching::gpu_preprocessing: GPU preprocessing is fully supported on this device.
2025-06-22T06:11:17.673485Z  INFO bevy_winit::system: Creating new window bevytest (0v0)
2025-06-22T06:11:19.007887Z  INFO bevytest: Going to game state
2025-06-22T06:11:19.008034Z  WARN bevy_ecs::error::handler: Encountered an error in command `<bevy_ecs::system::commands::entity_command::remove<bevy_ecs::hierarchy::ChildOf>::{{closure}} as bevy_ecs::error::command_handling::CommandWithEntity<core::result::Result<(), bevy_ecs::world::error::EntityMutableFetchError>>>::with_entity::{{closure}}`: The entity with ID 15v0 does not exist (enable `track_location` feature for more details)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorP-RegressionFunctionality that used to work but no longer does. Add a test for this!S-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions