Add SkipIfAny SystemParam - #25852
Open
BrainBacon wants to merge 3 commits into
Open
BrainBacon wants to merge 3 commits into
BrainBacon wants to merge 3 commits into
Conversation
Contributor
|
Welcome, new contributor! Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨ |
BrainBacon
force-pushed
the
feature/skip-if-any
branch
2 times, most recently
from
September 20, 2026 01:17
3e72cff to
27528d9
Compare
BrainBacon
force-pushed
the
feature/skip-if-any
branch
from
September 20, 2026 01:40
27528d9 to
1edcf9b
Compare
BrainBacon
force-pushed
the
feature/skip-if-any
branch
from
September 20, 2026 02:03
1edcf9b to
55e0eaa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Bevy has ergonomic system params for
SingleandPopulatedwhich skip system execution when the condition isn't met.Queryexpects any amount of resultsSingleis expecting one resultPopulatedis expecting more than one resultThis leaves space for a potential addition expecting zero results.
Relevant Discord discussion starting here
Solution
I added a new system param called
SkipIfAny<F>that will skip the system if any results match the provided filter.This does come with the caveat that there is no data returned by
SkipIfAny, so in order to avoid any unused warnings, users should add an underscore before their argument names.Alternatives Considered
Alternatively, a similar result can be achieved via a system run condition e.g.
not(any_match_filter::<F>). I find that still has value in certain situations like when running the same system in multiple contexts, but I findSkipIfAnyto be a nice way to ensure enforcement of the condition at the system level.We could potentially add something like
SkipIf<P: SystemParam>which would allow generalization for situations likeSkipIf<Populated<(), With<MyComponent>>and would achieve the same result. Ultimately I decided to submit this change anyway because it is really straightforward and a bit more ergonomic.SkipIfis still a potential solution that could be added alongside this PR.Testing
I've implemented a similar setup in my own game and refactored several systems that match the use case (although that implementation of
SkipIfAnyusesQuery::query_uncheckedinstead ofQuery::get_paramsinceTickis not accessible to outside consumers).I also refactored the Irradiance Volumes example since it was the best existing example that fit the use case and ran it to verify that it still functions as expected.
Future Work
Outside of a generalized solution, other ergonomic control flow helpers like this could be added such as one that skips unless more than one result is found or if only one is found. I haven't had need of these helpers in my own project, but if I find them valuable I can upstream them as well.
Showcase
In my own codebase
Before:
After: