Skip to content
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

Ergonomics of re-using run conditions #18312

Open
cBournhonesque opened this issue Mar 14, 2025 · 3 comments
Open

Ergonomics of re-using run conditions #18312

cBournhonesque opened this issue Mar 14, 2025 · 3 comments
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Needs-Design This issue requires design work to think about how it would best be accomplished

Comments

@cBournhonesque
Copy link
Contributor

cBournhonesque commented Mar 14, 2025

What problem does this solve or what need does it fill?

I often create run_conditions like so:

fn f(res: Res<S>) {}

which I can use when editing my schedule.

But then often I need to re-use the run_condition inside my Commands, or when I have World access.
Unfortunately I cannot directly re-use the run_condition because it has Res<S> in its arguments and not &Res<S>.

So currently I just do if world.get_resource::<S>.is_some_and(...)
where I basically repeat the logic.

I know that I could make a common function that takes &Res<S> as input to avoid the logic being repeated, but it's still a bit of ergonomic painpoint that i need to always do that. Also it means I would have to still have to manually call world.get_resource::<S> where in fact I'd just like to have something like

if world.run_condition_true(f)

Or maybe I can just use run_system_once? But i'm not sure about the performance implications. (also it requires &mut World instead of &World)

@cBournhonesque cBournhonesque added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Mar 14, 2025
@OleStrohm
Copy link

I don't think it works for the world situation, but for the &Res to Res this might help: https://docs.rs/bevy/latest/bevy/ecs/change_detection/struct.Res.html#method.clone

@cBournhonesque
Copy link
Contributor Author

That's true, that would help me re-create the original system params without needing to have a separate method for &Res<S>, but i would still love to just have world.run_condition_true(my_run_condition)

@alice-i-cecile alice-i-cecile removed the S-Needs-Triage This issue needs to be labelled label Mar 20, 2025
@alice-i-cecile
Copy link
Member

Can you call Res::reborrow?

@alice-i-cecile alice-i-cecile added the S-Needs-Design This issue requires design work to think about how it would best be accomplished label Mar 20, 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-Feature A new feature, making something new possible C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Needs-Design This issue requires design work to think about how it would best be accomplished
Projects
None yet
Development

No branches or pull requests

3 participants