1
+ #![ expect( deprecated) ]
2
+
1
3
mod range;
2
4
mod render_layers;
3
5
@@ -32,6 +34,7 @@ use super::NoCpuCulling;
32
34
/// `Visibility` to set the values of each entity's [`InheritedVisibility`] component.
33
35
#[ derive( Component , Clone , Copy , Reflect , Debug , PartialEq , Eq , Default ) ]
34
36
#[ reflect( Component , Default , Debug , PartialEq ) ]
37
+ #[ require( InheritedVisibility , ViewVisibility ) ]
35
38
pub enum Visibility {
36
39
/// An entity with `Visibility::Inherited` will inherit the Visibility of its [`Parent`].
37
40
///
@@ -171,8 +174,13 @@ impl ViewVisibility {
171
174
/// * To show or hide an entity, you should set its [`Visibility`].
172
175
/// * To get the inherited visibility of an entity, you should get its [`InheritedVisibility`].
173
176
/// * 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.
175
179
#[ 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
+ ) ]
176
184
pub struct VisibilityBundle {
177
185
/// The visibility of the entity.
178
186
pub visibility : Visibility ,
@@ -538,29 +546,16 @@ mod test {
538
546
use bevy_app:: prelude:: * ;
539
547
use bevy_hierarchy:: BuildChildren ;
540
548
541
- fn visibility_bundle ( visibility : Visibility ) -> VisibilityBundle {
542
- VisibilityBundle {
543
- visibility,
544
- ..Default :: default ( )
545
- }
546
- }
547
-
548
549
#[ test]
549
550
fn visibility_propagation ( ) {
550
551
let mut app = App :: new ( ) ;
551
552
app. add_systems ( Update , visibility_propagate_system) ;
552
553
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 ( ) ;
564
559
565
560
app. world_mut ( )
566
561
. entity_mut ( root1)
@@ -572,14 +567,11 @@ mod test {
572
567
. entity_mut ( root1_child2)
573
568
. add_children ( & [ root1_child2_grandchild1] ) ;
574
569
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 ( ) ;
583
575
584
576
app. world_mut ( )
585
577
. entity_mut ( root2)
@@ -650,14 +642,14 @@ mod test {
650
642
let mut app = App :: new ( ) ;
651
643
app. add_systems ( Update , visibility_propagate_system) ;
652
644
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 ( ) ;
658
650
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 ( ) ;
661
653
662
654
app. world_mut ( )
663
655
. entity_mut ( root1)
@@ -710,15 +702,15 @@ mod test {
710
702
711
703
// Set up an entity hierarchy.
712
704
713
- let id1 = world. spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
705
+ let id1 = world. spawn ( Visibility :: default ( ) ) . id ( ) ;
714
706
715
- let id2 = world. spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
707
+ let id2 = world. spawn ( Visibility :: default ( ) ) . id ( ) ;
716
708
world. entity_mut ( id1) . add_children ( & [ id2] ) ;
717
709
718
- let id3 = world. spawn ( visibility_bundle ( Visibility :: Hidden ) ) . id ( ) ;
710
+ let id3 = world. spawn ( Visibility :: Hidden ) . id ( ) ;
719
711
world. entity_mut ( id2) . add_children ( & [ id3] ) ;
720
712
721
- let id4 = world. spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
713
+ let id4 = world. spawn ( Visibility :: default ( ) ) . id ( ) ;
722
714
world. entity_mut ( id3) . add_children ( & [ id4] ) ;
723
715
724
716
// Test the hierarchy.
@@ -785,7 +777,7 @@ mod test {
785
777
schedule. add_systems ( visibility_propagate_system) ;
786
778
787
779
let parent = world. spawn ( ( ) ) . id ( ) ;
788
- let child = world. spawn ( VisibilityBundle :: default ( ) ) . id ( ) ;
780
+ let child = world. spawn ( Visibility :: default ( ) ) . id ( ) ;
789
781
world. entity_mut ( parent) . add_children ( & [ child] ) ;
790
782
791
783
schedule. run ( & mut world) ;
0 commit comments