-
-
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
Systems should be skipped if their resources cannot be fetched #15265
Comments
I really quite like this idea: I think it's generally a pretty robust solution. The design challenge here is: a) how do we provide warnings to users that their system isn't running because they forgot to initialize a resource or whatever |
+1 for this, this has bitten me before I guess a warning could tell you to explicitly use |
Discord notes from a conversation on 2024-09-17.
|
What about logging a warning on first run (or not-run?) that says more or less "system did not run because |
Yeah, I'm happy with that as an initial solution. |
I'd prefer for this to be an expected default that designs take into consideration cause it's more consistent with the behaviors of ECS. A diagnostic warning about missing resources is mostly going to be for transitioning from the old behavior. Is there a mechanism to have custom lints? If there is we could have one for all instances of
|
Another implication of this is that Unless we decide to do param validation before |
We could also add an associated const on the resource trait pub trait Resource: Send + Sync + 'static {
const NOISY: bool = false;
} With a helper attribute for the derive that sets this to |
Should
From @james7132 in discord |
I agree with @james7132 there: validation should be distinct from running the system, and be done by schedulers. @iiYese for custom lints, we'd need https://github.com/theBevyFlock/bevy_cli. I think I like the associated constant idea better though, although we should have various log levels (including panic), rather than just a |
@MiniaczQ points out that run conditions are systems too. If a run condition cannot be evaluated, it should be treated as if it returned false. |
@hymm points out that we should perform the validation checks as soon as possible, before spawning a task for the scheduler. For piped systems, al params must be checked at the start, and the whole piped collection of systems must be skipped if any are invalid. This is because piped systems are opaque to the schedule. |
For warnings, should we add a system config flag that decides whether to emit a warning? By default it would be |
Yeah, I was thinking about that in terms of system config initially, but I wasn't happy with the disabling ergonomics. I don't mind it existing, but in most cases I think that adding this at the resource / component level will better match the user intent and result in fewer bugs and boilerplate. |
Can we perhaps leverage module-filtering for this? Actually no, that doesn't make sense. |
I'm not sure about this cause for anything other than panic you'll get a wall of errors like WGPU which isn't much more helpful than a panic. Errors by default means you'll get a lot of opting out (which is indicative of a bad default). I think some people might be worried but would be surprised to find how sane this behavior actually is. |
Hmm. Panic might be a better default, yeah. I worry about adding more causes of "what the heck why isn't my system working": forgetting to add the system and forgetting to add the plugin are both super frustrating currently. |
Actually |
If this is considered, I'd prefer a const generic bool |
@iiYese we already have a warn_once family of macros for exactly this purpose. |
Adding an associated type or constant on Resource will break trait objects for it, so that needs to be considered carefully. |
Why would people have trait objects of an empty trait tho? 🤔 |
Inserting arbitrary components / resources is something I've seen people want to do. That said, we already do this with the |
That's once globally (per callsite), but we want to do it per system, and we want to have all warnings for the first run. |
Right, we'll need to add some variant of that that checks against a key (probably the system name in this case). |
Ah goodness duplicate comment, my browser had a stroke |
# Objective The goal of this PR is to introduce `SystemParam` validation in order to reduce runtime panics. Fixes #15265 ## Solution `SystemParam` now has a new method `validate_param(...) -> bool`, which takes immutable variants of `get_param` arguments. The returned value indicates whether the parameter can be acquired from the world. If parameters cannot be acquired for a system, it won't be executed, similarly to run conditions. This reduces panics when using params like `Res`, `ResMut`, etc. as well as allows for new, ergonomic params like #15264 or #15302. Param validation happens at the level of executors. All validation happens directly before executing a system, in case of normal systems they are skipped, in case of conditions they return false. Warning about system skipping is primitive and subject to change in subsequent PRs. ## Testing Two executor tests check that all executors: - skip systems which have invalid parameters: - piped systems get skipped together, - dependent systems still run correctly, - skip systems with invalid run conditions: - system conditions have invalid parameters, - system set conditions have invalid parameters.
I do think we should do this, and if we can get this behavior in place I'd prefer to encourage the use of the
Single
system param from #15264. This would go a long way to addressing the problem and ensuring non-panicking behavior by default without an ergonomics hit.Originally posted by @iiYese and @alice-i-cecile in #14275 (comment)
The text was updated successfully, but these errors were encountered: