bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Unable to use `distributive_run_if` with common conditions

Open st0rmbtw opened this issue 2 years ago • 3 comments

Bevy version

0.10.0

What you did

I wanted to add a chain of systems with run condition using distributive_run_if

app.add_systems(
    (
        update_cursor_position,
        update_info,
    )
    .chain()
    .distributive_run_if(resource_equals(UiVisibility(true)))
);

What went wrong

That code doesn't compile because distributive_run_if requires a condition to implement Clone, but all common conditions don't return Clone-able functions.

Additional information

error: the trait bound `impl for<'a> FnMut(bevy::prelude::Res<'a, ui::resources::UiVisibility>) -> bool: Clone` is not satisfied

st0rmbtw avatar Mar 12 '23 17:03 st0rmbtw

When fixing this, remember to change the ones in bevy_time and bevy_input too!

alice-i-cecile avatar Mar 12 '23 17:03 alice-i-cecile

We can't necessarily expect all of these conditions to implement Clone, right? Or would we constrain conditions like resource_equals to resources which implement Clone?

B-Reif avatar Mar 12 '23 17:03 B-Reif

This currently poses a problem for

  • resource_equals<T>
  • resource_exists_and_equals<T>
  • not

The resource conditions would have to expect the Resource type T to be Clone. The not condition returns a CombinatorSystem which isn't Clone.

B-Reif avatar Mar 12 '23 18:03 B-Reif