-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from 1 commit
24302cc
749a42b
e992e67
93ab94a
7fcad94
6027d4d
9bcad18
74a2c08
86c78a6
7d33c0d
15df851
48ab039
ffaea8f
5b4af1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ mod sealed { | |
| pub mod common_conditions { | ||
| use super::Condition; | ||
| use crate::{ | ||
| prelude::{Added, Changed, Component, Query}, | ||
| schedule::{State, States}, | ||
| system::{In, IntoPipeSystem, ReadOnlySystem, Res, Resource}, | ||
| }; | ||
|
|
@@ -141,4 +142,24 @@ pub mod common_conditions { | |
| { | ||
| condition.pipe(|In(val): In<bool>| !val) | ||
| } | ||
|
|
||
| /// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true` | ||
| /// if there are any entities with the added given component type. | ||
| /// | ||
| /// It's recommended to use this condition only if there is only a few entities | ||
| /// with the component `T`. Otherwise this check could be expensive and hold | ||
| /// up the executor preventing it from running any systems during the check. | ||
| pub fn any_component_added<T: Component>() -> impl FnMut(Query<(), Added<T>>) -> bool { | ||
| move |query: Query<(), Added<T>>| !query.is_empty() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
|
|
||
| /// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true` | ||
| /// if there are any entities with the changed given component type. | ||
Shatur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// It's recommended to use this condition only if there is only a few entities | ||
| /// with the component `T`. Otherwise this check could be expensive and hold | ||
| /// up the executor preventing it from running any systems during the check. | ||
| pub fn any_component_changed<T: Component>() -> impl FnMut(Query<(), Changed<T>>) -> bool { | ||
| move |query: Query<(), Changed<T>>| !query.is_empty() | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.