-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsA-UIGraphical user interfaces, styles, layouts, and widgetsGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorS-Needs-InvestigationThis issue requires detective work to figure out what's going wrongThis issue requires detective work to figure out what's going wrong
Description
Bevy version
What you did
use bevy::{input::common_conditions::*, prelude::*};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.insert_resource(ClearColor(Color::srgb(0.9, 0.9, 0.9)))
.add_systems(Startup, setup)
.add_systems(Update, show.run_if(input_just_pressed(KeyCode::Space)))
.run();
}
fn setup(mut commands: Commands) {
commands.spawn(Camera2d);
commands.spawn((
Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
..Default::default()
},
// Yes, all this hierarchy nodes are required to trigger the issue.
children![(Node::default(), children![Node::default()])],
));
}
fn show(mut commands: Commands, root_entity: Single<Entity, (With<Node>, Without<ChildOf>)>) {
info!("showing dialog");
commands.spawn((
ChildOf {
parent: *root_entity,
},
Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..Default::default()
},
BackgroundColor(Color::BLACK),
// Uncommend this `Dialog` component and the text won't be displayed.
// Dialog,
children![(
Node::default(),
children![Text::new("This text should be displayed")]
)],
));
}
#[derive(Component, Default)]
#[require(
Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..Default::default()
},
BackgroundColor(Color::BLACK),
)]
struct Dialog;What went wrong
With very specific hierarchy setups (see code comments), using required components sometimes behaves differently from inserting the necessary components directly. If you uncomment Dialog insertion, the text won't be displayed.
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsA-UIGraphical user interfaces, styles, layouts, and widgetsGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorS-Needs-InvestigationThis issue requires detective work to figure out what's going wrongThis issue requires detective work to figure out what's going wrong