Cannot build a runtime observer system using a closure
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## 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, query: Query| {},
);
```
## 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, query: Query) { }
```
```
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| {});
```
## 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
Contributor guide
Assessment
This issue has not been assessed yet.