1+ #![ expect( deprecated) ]
2+
13mod range;
24mod render_layers;
35
@@ -32,6 +34,7 @@ use super::NoCpuCulling;
3234/// `Visibility` to set the values of each entity's [`InheritedVisibility`] component.
3335#[ derive( Component , Clone , Copy , Reflect , Debug , PartialEq , Eq , Default ) ]
3436#[ reflect( Component , Default , Debug , PartialEq ) ]
37+ #[ require( InheritedVisibility , ViewVisibility ) ]
3538pub enum Visibility {
3639 /// An entity with `Visibility::Inherited` will inherit the Visibility of its [`Parent`].
3740 ///
@@ -171,8 +174,13 @@ impl ViewVisibility {
171174/// * To show or hide an entity, you should set its [`Visibility`].
172175/// * To get the inherited visibility of an entity, you should get its [`InheritedVisibility`].
173176/// * For visibility hierarchies to work correctly, you must have both all of [`Visibility`], [`InheritedVisibility`], and [`ViewVisibility`].
174- /// * You may use the [`VisibilityBundle`] to guarantee this.
177+ /// * ~~You may use the [`VisibilityBundle`] to guarantee this.~~ [`VisibilityBundle`] is now deprecated.
178+ /// [`InheritedVisibility`] and [`ViewVisibility`] are automatically inserted whenever [`Visibility`] is inserted.
175179#[ derive( Bundle , Debug , Clone , Default ) ]
180+ #[ deprecated(
181+ since = "0.15.0" ,
182+ note = "Use the `Visibility` component instead. Inserting it will now also insert `InheritedVisibility` and `ViewVisibility` automatically."
183+ ) ]
176184pub struct VisibilityBundle {
177185 /// The visibility of the entity.
178186 pub visibility : Visibility ,
@@ -538,29 +546,16 @@ mod test {
538546 use bevy_app:: prelude:: * ;
539547 use bevy_hierarchy:: BuildChildren ;
540548
541- fn visibility_bundle ( visibility : Visibility ) -> VisibilityBundle {
542- VisibilityBundle {
543- visibility,
544- ..Default :: default ( )
545- }
546- }
547-
548549 #[ test]
549550 fn visibility_propagation ( ) {
550551 let mut app = App :: new ( ) ;
551552 app. add_systems ( Update , visibility_propagate_system) ;
552553
553- let root1 = app
554- . world_mut ( )
555- . spawn ( visibility_bundle ( Visibility :: Hidden ) )
556- . id ( ) ;
557- let root1_child1 = app. world_mut ( ) . spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
558- let root1_child2 = app
559- . world_mut ( )
560- . spawn ( visibility_bundle ( Visibility :: Hidden ) )
561- . id ( ) ;
562- let root1_child1_grandchild1 = app. world_mut ( ) . spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
563- let root1_child2_grandchild1 = app. world_mut ( ) . spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
554+ let root1 = app. world_mut ( ) . spawn ( Visibility :: Hidden ) . id ( ) ;
555+ let root1_child1 = app. world_mut ( ) . spawn ( Visibility :: default ( ) ) . id ( ) ;
556+ let root1_child2 = app. world_mut ( ) . spawn ( Visibility :: Hidden ) . id ( ) ;
557+ let root1_child1_grandchild1 = app. world_mut ( ) . spawn ( Visibility :: default ( ) ) . id ( ) ;
558+ let root1_child2_grandchild1 = app. world_mut ( ) . spawn ( Visibility :: default ( ) ) . id ( ) ;
564559
565560 app. world_mut ( )
566561 . entity_mut ( root1)
@@ -572,14 +567,11 @@ mod test {
572567 . entity_mut ( root1_child2)
573568 . add_children ( & [ root1_child2_grandchild1] ) ;
574569
575- let root2 = app. world_mut ( ) . spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
576- let root2_child1 = app. world_mut ( ) . spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
577- let root2_child2 = app
578- . world_mut ( )
579- . spawn ( visibility_bundle ( Visibility :: Hidden ) )
580- . id ( ) ;
581- let root2_child1_grandchild1 = app. world_mut ( ) . spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
582- let root2_child2_grandchild1 = app. world_mut ( ) . spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
570+ let root2 = app. world_mut ( ) . spawn ( Visibility :: default ( ) ) . id ( ) ;
571+ let root2_child1 = app. world_mut ( ) . spawn ( Visibility :: default ( ) ) . id ( ) ;
572+ let root2_child2 = app. world_mut ( ) . spawn ( Visibility :: Hidden ) . id ( ) ;
573+ let root2_child1_grandchild1 = app. world_mut ( ) . spawn ( Visibility :: default ( ) ) . id ( ) ;
574+ let root2_child2_grandchild1 = app. world_mut ( ) . spawn ( Visibility :: default ( ) ) . id ( ) ;
583575
584576 app. world_mut ( )
585577 . entity_mut ( root2)
@@ -650,14 +642,14 @@ mod test {
650642 let mut app = App :: new ( ) ;
651643 app. add_systems ( Update , visibility_propagate_system) ;
652644
653- let root1 = app. world_mut ( ) . spawn ( visibility_bundle ( Visible ) ) . id ( ) ;
654- let root1_child1 = app. world_mut ( ) . spawn ( visibility_bundle ( Inherited ) ) . id ( ) ;
655- let root1_child2 = app. world_mut ( ) . spawn ( visibility_bundle ( Hidden ) ) . id ( ) ;
656- let root1_child1_grandchild1 = app. world_mut ( ) . spawn ( visibility_bundle ( Visible ) ) . id ( ) ;
657- let root1_child2_grandchild1 = app. world_mut ( ) . spawn ( visibility_bundle ( Visible ) ) . id ( ) ;
645+ let root1 = app. world_mut ( ) . spawn ( Visible ) . id ( ) ;
646+ let root1_child1 = app. world_mut ( ) . spawn ( Inherited ) . id ( ) ;
647+ let root1_child2 = app. world_mut ( ) . spawn ( Hidden ) . id ( ) ;
648+ let root1_child1_grandchild1 = app. world_mut ( ) . spawn ( Visible ) . id ( ) ;
649+ let root1_child2_grandchild1 = app. world_mut ( ) . spawn ( Visible ) . id ( ) ;
658650
659- let root2 = app. world_mut ( ) . spawn ( visibility_bundle ( Inherited ) ) . id ( ) ;
660- let root3 = app. world_mut ( ) . spawn ( visibility_bundle ( Hidden ) ) . id ( ) ;
651+ let root2 = app. world_mut ( ) . spawn ( Inherited ) . id ( ) ;
652+ let root3 = app. world_mut ( ) . spawn ( Hidden ) . id ( ) ;
661653
662654 app. world_mut ( )
663655 . entity_mut ( root1)
@@ -710,15 +702,15 @@ mod test {
710702
711703 // Set up an entity hierarchy.
712704
713- let id1 = world. spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
705+ let id1 = world. spawn ( Visibility :: default ( ) ) . id ( ) ;
714706
715- let id2 = world. spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
707+ let id2 = world. spawn ( Visibility :: default ( ) ) . id ( ) ;
716708 world. entity_mut ( id1) . add_children ( & [ id2] ) ;
717709
718- let id3 = world. spawn ( visibility_bundle ( Visibility :: Hidden ) ) . id ( ) ;
710+ let id3 = world. spawn ( Visibility :: Hidden ) . id ( ) ;
719711 world. entity_mut ( id2) . add_children ( & [ id3] ) ;
720712
721- let id4 = world. spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
713+ let id4 = world. spawn ( Visibility :: default ( ) ) . id ( ) ;
722714 world. entity_mut ( id3) . add_children ( & [ id4] ) ;
723715
724716 // Test the hierarchy.
@@ -785,7 +777,7 @@ mod test {
785777 schedule. add_systems ( visibility_propagate_system) ;
786778
787779 let parent = world. spawn ( ( ) ) . id ( ) ;
788- let child = world. spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
780+ let child = world. spawn ( Visibility :: default ( ) ) . id ( ) ;
789781 world. entity_mut ( parent) . add_children ( & [ child] ) ;
790782
791783 schedule. run ( & mut world) ;
0 commit comments