-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add any_component_removed
condition
#8326
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
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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -143,6 +143,7 @@ pub mod common_conditions { | |||||||
change_detection::DetectChanges, | ||||||||
event::{Event, EventReader}, | ||||||||
prelude::{Component, Query, With}, | ||||||||
removal_detection::RemovedComponents, | ||||||||
schedule::{State, States}, | ||||||||
system::{IntoSystem, Res, Resource, System}, | ||||||||
}; | ||||||||
|
@@ -893,6 +894,17 @@ pub mod common_conditions { | |||||||
move |query: Query<(), With<T>>| !query.is_empty() | ||||||||
} | ||||||||
|
||||||||
/// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true` | ||||||||
/// if there are any entities with the given component type removed. | ||||||||
pub fn any_component_removed<T: Component>() -> impl FnMut(RemovedComponents<T>) -> bool { | ||||||||
// `RemovedComponents` based on events and therefore events need to be consumed, | ||||||||
// so that there are no false positives on subsequent calls of the run condition. | ||||||||
// Simply checking `is_empty` would not be enough. | ||||||||
// PERF: note that `count` is efficient (not actually looping/iterating), | ||||||||
// due to Bevy having a specialized implementation for events. | ||||||||
move |mut removals: RemovedComponents<T>| !removals.iter().count() != 0 | ||||||||
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.
Suggested change
This otherwise potentially does a full traversal. 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. This contradicts the perf note above. I would still prefer to remove the perf note and just use is_empty though. 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. Oh I completely forgot we overrode the default implementations for those. Agreed on the use of 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.
|
||||||||
} | ||||||||
|
||||||||
/// Generates a [`Condition`](super::Condition) that inverses the result of passed one. | ||||||||
/// | ||||||||
/// # Example | ||||||||
|
Uh oh!
There was an error while loading. Please reload this page.