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

Introduce Populated system param #15302

Closed
MiniaczQ opened this issue Sep 19, 2024 · 5 comments · Fixed by #15488
Closed

Introduce Populated system param #15302

MiniaczQ opened this issue Sep 19, 2024 · 5 comments · Fixed by #15488
Assignees
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! X-Contentious There are nontrivial implications that should be thought through

Comments

@MiniaczQ
Copy link
Contributor

MiniaczQ commented Sep 19, 2024

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

There have been many requests to not run systems if there is nothing to process (in a query).
The Populated system param would do exactly that.

What solution would you like?

Add Populated system param that fails validation if query is empty.

@MiniaczQ MiniaczQ 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 X-Contentious There are nontrivial implications that should be thought through and removed S-Needs-Triage This issue needs to be labelled labels Sep 19, 2024
@alice-i-cecile
Copy link
Member

I'm in favor of this existing: seems quite useful once #15276 is merged. This is a sibling to #15264.

I'd be interested in adding a NonEmptyEventReader as well, either in the same PR or in a separate one.

@benfrankel
Copy link
Contributor

Bikeshedding, but would QueryNonEmpty be a better name? It'd be next to Query and QuerySingle alphabetically and in code-completion.

@alice-i-cecile
Copy link
Member

I think that's a bit better, yeah.

@MiniaczQ
Copy link
Contributor Author

I prefer proper spelling, all of them will show up when typing "Query"
I'm fine either way

@MiniaczQ
Copy link
Contributor Author

Second thoughts, maybe we should skip Query entirely, assuming we're moving more things to entities, this will naturally show up more so we don't need to be worried about awareness

github-merge-queue bot pushed a commit that referenced this issue Sep 23, 2024
# 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.
@MiniaczQ MiniaczQ added the S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! label Sep 23, 2024
@MiniaczQ MiniaczQ changed the title Introduce NonEmptyQuery system param Introduce Populated system param Sep 29, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 30, 2024
# Objective

Add a `Populated` system parameter that acts like `Query`, but prevents
system from running if there are no matching entities.

Fixes: #15302

## Solution

Implement the system param which newtypes the `Query`.
The only change is new validation, which fails if query is empty.

The new system param is used in `fallible_params` example.

## Testing

Ran `fallible_params` example.

---------

Co-authored-by: Alice Cecile <[email protected]>
robtfm pushed a commit to robtfm/bevy that referenced this issue Oct 4, 2024
# Objective

Add a `Populated` system parameter that acts like `Query`, but prevents
system from running if there are no matching entities.

Fixes: bevyengine#15302

## Solution

Implement the system param which newtypes the `Query`.
The only change is new validation, which fails if query is empty.

The new system param is used in `fallible_params` example.

## Testing

Ran `fallible_params` example.

---------

Co-authored-by: Alice Cecile <[email protected]>
@MiniaczQ MiniaczQ self-assigned this Oct 20, 2024
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 S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! X-Contentious There are nontrivial implications that should be thought through
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants