Skip to content

RemovedComponents doesn't work in FixedUpdate #16520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mirsella opened this issue Nov 26, 2024 · 2 comments
Open

RemovedComponents doesn't work in FixedUpdate #16520

mirsella opened this issue Nov 26, 2024 · 2 comments
Labels
A-ECS Entities, components, systems, and events A-Time Involves time keeping and reporting C-Bug An unexpected or incorrect behavior S-Needs-Design This issue requires design work to think about how it would best be accomplished

Comments

@mirsella
Copy link
Contributor

mirsella commented Nov 26, 2024

hello

Bevy version

0.14.2

What you did

have a system remove a Component in an Update system.
use a RemovedComponents in a FixedUpdate system.

What went wrong

RemovedComponents.read() doesn't return any entities

Additional information

it works by just moving the system from FixedUpdate to Update

there has been an issue about events not working in FixedUpdate #7691 fixed in this PR #10077. someone has talked about it in the pr and issue. here is a comment about it in the pr #10077 (comment).

if making events like RemovedComponents works in FixedUpdate too much of a drawback, i think there should be a clear indication on the docs, and even better, a bevy warning about it, since now it just silently fails.

thanks

@mirsella mirsella added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Nov 26, 2024
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events S-Needs-Design This issue requires design work to think about how it would best be accomplished A-Time Involves time keeping and reporting and removed S-Needs-Triage This issue needs to be labelled labels Nov 26, 2024
@alice-i-cecile
Copy link
Member

I expect that the best way to solve / close this is actually via a rewrite to use observers, ala #13928. I would definitely suggest that for now as a workaround.

@mirsella
Copy link
Contributor Author

i guess this can be used as reproduction:

use bevy::prelude::*;
fn main() {
    let mut app = App::new();
    app.add_plugins(DefaultPlugins)
        .add_systems(Startup, |mut commands: Commands| {
            (0..10).for_each(|_| {
                commands.spawn(Foo);
            })
        })
        .add_systems(
            Update,
            |mut commands: Commands, q_foo: Query<Entity, With<Foo>>| {
                if let Some(entity) = q_foo.iter().next() {
                    commands.entity(entity).despawn();
                }
            },
        )
        .add_systems(FixedUpdate, |rm: RemovedComponents<Foo>| {
            println!("count: {}", rm.len());
        })
        .run();
}

#[derive(Component)]
struct Foo;

when running the removedcomponents system with Update we get 10 times a count 1 but with FixedUpdate not all of them are shown (6 on my computer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events A-Time Involves time keeping and reporting C-Bug An unexpected or incorrect behavior S-Needs-Design This issue requires design work to think about how it would best be accomplished
Projects
None yet
Development

No branches or pull requests

2 participants