Skip to content

Spawing many Entities and then despawing them leads to NoSuchEntity. #369

Closed
@kakoeimon

Description

@kakoeimon

I was trying to create a minimal project for another problem an I came upon this.
The minimal example project is the example ui/text with those lines:

`struct Item {
max_time: f32,
time: f32,
}

fn add_items(mut commands: Commands) {
for _ in 0..1000 {
commands.spawn((Item {max_time: 1.0, time: 0.0}, ));
}

}

fn update_items(mut commands: Commands, time: Res, mut query: Query<(&mut Item, Entity)>) {
let mut num = 0;
for (mut item, e) in &mut query.iter() {
num += 1;
item.time += time.delta_seconds;
if item.time >= item.max_time {
commands.despawn(e);
}
}
println!("number of items : {}", num);
}`

After a while I get:

thread 'main' panicked at 'calledResult::unwrap()on anErrvalue: NoSuchEntity', C:\Users\kakoeimon\.cargo\git\checkouts\bevy-f7ffde730c324c74\89a1d36\crates\bevy_ecs\src\system\commands.rs:75:36 note: run withRUST_BACKTRACE=1environment variable to display a backtrace error: process didn't exit successfully:target\debug\no_such_entity.exe(exit code: 101)

The minimal example project

no_such_entity.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions