IyesGames / iyes_loopless

Alternatives to Bevy States, FixedTimestep, Run Criteria, that do not use "stage looping" and are composable
Other
249 stars 27 forks source link

Can't use system.after() within a ConditionSet #33

Closed scambier closed 2 years ago

scambier commented 2 years ago

Hello, I have an issue with systems ordering within a ConditionSet.

With a standard SystemSet, this works:

.with_system_set(
    SystemSet::new()
        .label("update")
        .with_system(movement::apply_velocity)
        .with_system(movement::constrain_entities.after(movement::apply_velocity)),
)

But with a ConditionSet this doesn't:

.with_system_set(
    ConditionSet::new()
        .label("update")
        .run_if(state_is_in_game)
        .with_system(movement::apply_velocity)
        .with_system(movement::constrain_entities.after(movement::apply_velocity)) // Error on this line
        .into(),
)

the trait bound ParallelSystemDescriptor: IntoSystem<(), (), _> is not satisfied the trait AddConditionalToSet<ConditionSystemSet, ()> is implemented for ConditionalSystemDescriptor required because of the requirements on the impl of IntoConditionalSystem<_> for ParallelSystemDescriptor required because of the requirements on the impl of AddConditionalToSet<ConditionSystemSet, _> for ParallelSystemDescriptorrustcE0277

If I use a .into() after the .after(), the error changes to

type annotations needed cannot infer type of the type parameter S declared on the associated function with_systemrustcE0282 mod.rs(52, 37): consider specifying the generic arguments: ::<S, P>

Edit: I can use .chain() for this specific case, but being able to use .after() and .before() within a ConditionSet would be better

inodentry commented 2 years ago

You are correct. label/before/after cannot be used on a specific system inside a ConditionSet.

If you need system ordering on individual systems, you have to add them individually, one by one, without using a ConditionSet.

Remember that on individual systems, the labels/ordering must come at the end, after the run conditions.


Also, on an unrelated note, I notice another issue in your code. before/after do not work with system names, only with labels. .after(another_system) will just print a runtime warning that it cannot find another_system. You have to create labels and do your ordering with labels.


I am sorry for the stupid API restrictions and syntax requirements. It's unfortunate. These Bevy APIs were incredibly difficult to work with (private with locked down access) and this was the only way I could make things work.

scambier commented 2 years ago

Thanks for the answer :)

Also, on an unrelated note, I notice another issue in your code

Heh, it looked like it worked, I guess it was just luck when I tried it :p