-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Conditional execution of systems using Resources #434
Conversation
…esources will only be called if all fetched Resources are Some(). This is done to implement ChangedRes, which is Some iff the Resource has been changed.
just my opinion, but this API feels awkward to me. |
There is a certain amount of value in abstracting this out, but in my opinion the abstraction isn't worth the additional cognitive load. I think porting your example above to just use an if statement illustrates this: struct Person;
struct Name(String);
struct GreetTimer(Timer);
struct Frame(u32);
struct Paused(bool);
fn fixed_timestep(time: Res<Time>, mut timer: ResMut<GreetTimer>, mut frame: ResMut<Frame>) {
timer.0.tick(time.delta_seconds);
if timer.0.finished {
frame.0 += 1;
}
}
fn greet_people(paused: Res<Paused>, frame: ChangedRes<Frame>, _person: &Person, name: &Name) {
if paused.0 { return }
println!("hello {} on frame {}!", name.0, frame.0);
} This reads much more clearly. I do think it makes sense to eventually allow enabling/disabling systems, but i think it should happen at the schedule and/or scene level. |
I think I'll close this for now. I really appreciate that you explored the idea as we now have a concrete example of one of our options in this space. But I do want to explore our other options too. We can re-open this later if it turns out this is our best option. |
No problem, I learned a lot implementing this. Nonetheless, I think that this is not so unnatural once we are used to using systems with Changed and ChangedRes. The name may be poorly chosen, "OnlyIfRes" or "IfRes" may be better. The comparison that you make with if paused.0 { return } is not really fair in my opinion because you may be borrowing archetypes and iterating on a lot of entities just to return? |
On the subject of:
#128
This enables the user to define systems that will only be called on certain conditions, stored in Resources. This is implemented with the same logic as the ChangedRes resource query defined in #388.
I added an example of what can be done with FlagRes and ChangedRes by modifying the "greet" example from the Bevy book. The greet_people system can be rewritten as a for_each system, run on a change of the Frame resource and its call can be blocked by the Paused Resource: