-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Create a When
system param wrapper for skipping systems that fail validation
#18516
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
Comments
We may also want a One use case I had in mind for generic The issue there is that regular I wanted to be able to write that using ... but |
Single, Option, Populated already have that behavior, no? it says so: |
This proposal would change the semantics so that they error (see point 1) unless combined with a |
The |
Agreed |
So |
I think the intention of the original behavior of Although then the ideal behavior for (I do prefer having a blanket |
I'm fine with any of this but, for the record, I don't think we should be shipping any other changes to this system in 0.16 now that Alice has basically fixed it. |
…alidation (#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 #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 <[email protected]> Co-authored-by: Zachary Harrold <[email protected]> Co-authored-by: François Mockers <[email protected]>
# Objective Provide a generic `impl SystemParam for Option<P>` that uses system parameter validation. This immediately gives useful impls for params like `EventReader` and `GizmosState` that are defined in terms of `Res`. It also allows third-party system parameters to be usable with `Option`, which was previously impossible due to orphan rules. Note that this is a behavior change for `Option<Single>`. It currently fails validation if there are multiple matching entities, but with this change it will pass validation and produce `None`. Also provide an impl for `Result<P, SystemParamValidationError>`. This allows systems to inspect the error if necessary, either for bubbling it up or for checking the `skipped` flag. Fixes #12634 Fixes #14949 Related to #18516 ## Solution Add generic `SystemParam` impls for `Option` and `Result`, and remove the impls for specific types. Update documentation and `fallible_params` example with the new semantics for `Option<Single>`.
…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 <[email protected]> Co-authored-by: Zachary Harrold <[email protected]> Co-authored-by: François Mockers <[email protected]>
# Objective Provide a generic `impl SystemParam for Option<P>` that uses system parameter validation. This immediately gives useful impls for params like `EventReader` and `GizmosState` that are defined in terms of `Res`. It also allows third-party system parameters to be usable with `Option`, which was previously impossible due to orphan rules. Note that this is a behavior change for `Option<Single>`. It currently fails validation if there are multiple matching entities, but with this change it will pass validation and produce `None`. Also provide an impl for `Result<P, SystemParamValidationError>`. This allows systems to inspect the error if necessary, either for bubbling it up or for checking the `skipped` flag. Fixes bevyengine#12634 Fixes bevyengine#14949 Related to bevyengine#18516 ## Solution Add generic `SystemParam` impls for `Option` and `Result`, and remove the impls for specific types. Update documentation and `fallible_params` example with the new semantics for `Option<Single>`.
I really like the optional system param thing, I was wondering about that myself.
I'm less sold on having a single skipping wrapper; however if we did decide to go with it my vote would be to call it
When<T>
(eg.When<Res<MyResource>>
orWhen<Single<Window>>
orWhen<Populated<MyComponent>>
) to indicate that this system runs when the parameter is valid.Just having a few separate wrappers with this functionality built in seems fine. Having a dedicated
When<T>
wrapper does increase flexibility somewhat... There are situations where users may want their app to panic if they don't have exactly one entity with a single value, I think I've had situations where I'd have liked to enforce that invariant before.Just so we are all on the same page, your proposed semantics would basically be:
Option<T>
wrapper turns an error into a successfulNone
parameter.When<T>
wrapper skips the system when it encounters an error.I don't hate that. One slightly awkward result is the behavior of
Option<When<T>>
andWhen<Option<T>>
. Should the former skip?Originally posted by @NthTensor in #18504 (comment)
The text was updated successfully, but these errors were encountered: