Skip to content

Cannot build a runtime observer system using a closure #19284

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
Stumblinbear opened this issue May 18, 2025 · 0 comments
Open

Cannot build a runtime observer system using a closure #19284

Stumblinbear opened this issue May 18, 2025 · 0 comments
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Investigation This issue requires detective work to figure out what's going wrong

Comments

@Stumblinbear
Copy link

Bevy version

0.16

What you did

I'm attempting to create an observer system at runtime that needs to query components created at runtime.

let system = (QueryParamBuilder::new(|builder| {
    builder.mut_id(dynamic_component_id);
}),)
    .build_state(world)
    .build_system_with_input(
        |trigger: Trigger<OnAdd>, query: Query<FilteredEntityMut>| {},
    );

What went wrong

When calling build_system_with_input with a closure, I get the following error:

help: the trait `bevy::prelude::SystemParamFunction<_>` is not implemented for closure

However, if this is broken out into a free function with the same signature and called that way, it works fine:

fn dynamic_observer_system(trigger: Trigger<OnAdd>, query: Query<FilteredEntityMut>) { }
let system = (QueryParamBuilder::new(|builder| {
    builder.mut_id(dynamic_component_id);
}),)
    .build_state(world)
    .build_system_with_input(dynamic_observer_system);

It is not necessary to have the Query to reproduce the issue, but I included it for a more accurate view of what I was attempting to accomplish. This still fails:

let system = ().build_state(world).build_system_with_input(|trigger: Trigger<OnAdd>| {});

Additional information

This only seems to apply to observer systems; creating non-observer systems with a closure using build_system or build_system_with_input seems to work perfectly fine.

I was hoping to capture a couple of variables in the closure for use in the system, but this limitation means I have to store those extra variables in a resource and do a lookup each time it's triggered. I'm unsure what specifically is causing this issue, as the various generic bounds and impls are difficult to understand from an outsider perspective

@Stumblinbear Stumblinbear added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels May 18, 2025
@greeble-dev greeble-dev added A-ECS Entities, components, systems, and events S-Needs-Investigation This issue requires detective work to figure out what's going wrong D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes and removed S-Needs-Triage This issue needs to be labelled labels May 19, 2025
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 C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Investigation This issue requires detective work to figure out what's going wrong
Projects
None yet
Development

No branches or pull requests

2 participants