Create a When system param wrapper for skipping systems that fail validation#18765
Create a When system param wrapper for skipping systems that fail validation#18765mockersf merged 9 commits intobevyengine:mainfrom
When system param wrapper for skipping systems that fail validation#18765Conversation
I really don't think we should do this, and would prefer to spin this out into a separate PR. These are useful, terse helpers for a common pattern and I would really like to stop changing their semantics in breaking ways. |
Sure, I'll remove that from this PR. I do still think it's worth doing, though! The panicking version of But I will feel really bad for all the folks trying to use |
... the other way to get consistency is to make |
Mhmm :) This is too late in the 0.16 cycle for this to land, so I'm reluctant to change the behavior yet again. Thanks for splitting it out though; this is a much simpler and uncontroversial helper on its own. |
bushrat011899
left a comment
There was a problem hiding this comment.
Love it, just a suggestion for documentation. Not blocking at all.
Co-authored-by: Zachary Harrold <zac@harrold.com.au>
Split comment onto multiple lines to avoid horizontal scrolling in docs.
…alidation (bevyengine#18765) # Objective Create a `When` system param wrapper for skipping systems that fail validation. Currently, the `Single` and `Populated` parameters cause systems to skip when they fail validation, while the `Res` family causes systems to error. Generalize this so that any fallible parameter can be used either to skip a system or to raise an error. A parameter used directly will always raise an error, and a parameter wrapped in `When<P>` will always cause the system to be silently skipped. ~~Note that this changes the behavior for `Single` and `Populated`. The current behavior will be available using `When<Single>` and `When<Populated>`.~~ Fixes bevyengine#18516 ## Solution Create a `When` system param wrapper that wraps an inner parameter and converts all validation errors to `skipped`. ~~Change the behavior of `Single` and `Populated` to fail by default.~~ ~~Replace in-engine use of `Single` with `When<Single>`. I updated the `fallible_systems` example, but not all of the others. The other examples I looked at appeared to always have one matching entity, and it seemed more clear to use the simpler type in those cases.~~ --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: Zachary Harrold <zac@harrold.com.au> Co-authored-by: François Mockers <mockersf@gmail.com>
Objective
Create a
Whensystem param wrapper for skipping systems that fail validation.Currently, the
SingleandPopulatedparameters cause systems to skip when they fail validation, while theResfamily causes systems to error. Generalize this so that any fallible parameter can be used either to skip a system or to raise an error. A parameter used directly will always raise an error, and a parameter wrapped inWhen<P>will always cause the system to be silently skipped.Note that this changes the behavior forSingleandPopulated. The current behavior will be available usingWhen<Single>andWhen<Populated>.Fixes #18516
Solution
Create a
Whensystem param wrapper that wraps an inner parameter and converts all validation errors toskipped.Change the behavior ofSingleandPopulatedto fail by default.Replace in-engine use ofSinglewithWhen<Single>. I updated thefallible_systemsexample, but not all of the others. The other examples I looked at appeared to always have one matching entity, and it seemed more clear to use the simpler type in those cases.