-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add common component conditions #7711
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise this check could be expensive and hold up the executor preventing it from running any systems during the check.
I think this can be more clearly phrased by replacing your warning with the following:
Run conditions are evaluated on the main thread, blocking any other systems from running.
This run condition is relatively expensive, as it iterates over every entity with this component.
As a result, you likely only want to use this run condition when the number of entitities with the componentT
is small.
One more request: can we have the same flavor of run condition, but for RemovedComponent<T>
?
I like it!
I think we switched to events for this: #5680 |
That PR was effectively non-breaking :) The |
Right, missed that it was an internal change. Will add the condition. |
We probably should add |
037bc82
to
749a42b
Compare
/// This run condition is relatively expensive, as it iterates over every entity with this component. | ||
/// As a result, you likely only want to use this run condition when the number of entitities with the component `T` is small. | ||
pub fn any_component_added<T: Component>() -> impl FnMut(Query<(), Added<T>>) -> bool { | ||
move |query: Query<(), Added<T>>| !query.is_empty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These potentially do a full world scan in the multithreaded executor, which not only runs single threaded but blocks any further system's run conditions from being evaluated and tasks launched. The only early return is if no archetypes match the query, everything else does a full scan, and will scale linearly with the number of those components in the world. This is relatively easy performance footgun, same with the other condition below.
Even with it documented, I still don't think it's a good idea to readily provide this to users without some form of archetype-level change detection optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this is what I mentioned in the description. I thought it's fine if documented. But your concern is exactly why it wasn't included in #7579.
Co-authored-by: Ida "Iyes" <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggesting better wording for the doc comments!
Co-authored-by: Ida "Iyes" <[email protected]>
Co-authored-by: Ida "Iyes" <[email protected]>
Thanks! |
Other than the little things I pointed out above, I approve! Given the warning in the documentation, I think this is worth including in Bevy. As implemented, if, in the future, change detection gets optimized so that the queries don't have to iterate, this API will just magically become fast, and we can remove the perf warning. :) |
Added helper extracted from #7711. that PR contains some controversy conditions, but this one should be good to go. --- ## Changelog ### Added - `any_component_removed` condition. --------- Co-authored-by: François <[email protected]>
I moved non-controversial |
It was decided to not implement it, closing. |
Add two useful common run conditions for components similar to
any_with_component
from #7579. Unlikeany_with_component
these two conditions could be potentially expensive, but super useful if user knows that there is only a few entities with a component.Changelog
Added
any_component_added
andany_component_changed
.