Skip to content

Commit 88700f3

Browse files
committed
Add mutating toggle method to Visibility component (#6268)
# Objective Make toggling the visibility of an entity slightly more convenient. ## Solution Add a mutating `toggle` method to the `Visibility` component ```rust fn my_system(mut query: Query<&mut Visibility, With<SomeMarker>>) { let mut visibility = query.single_mut(); // before: visibility.is_visible = !visibility.is_visible; // after: visibility.toggle(); } ``` ## Changelog ### Added - Added a mutating `toggle` method to the `Visibility` component
1 parent b840ba3 commit 88700f3

File tree

1 file changed

+5
-0
lines changed
  • crates/bevy_render/src/view/visibility

1 file changed

+5
-0
lines changed

crates/bevy_render/src/view/visibility/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ impl Visibility {
4747

4848
/// A [`Visibility`], set as invisible.
4949
pub const INVISIBLE: Self = Visibility { is_visible: false };
50+
51+
/// Toggle the visibility.
52+
pub fn toggle(&mut self) {
53+
self.is_visible = !self.is_visible;
54+
}
5055
}
5156

5257
/// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering

0 commit comments

Comments
 (0)