I have a mystery unparented UI element that is created as an unintended byproduct of another system that otherwise works smoothly. Here's the code:
Eventually this system will put an image of an item in the item slots. For now it just puts the entity id in there.
#[derive(Component)]
struct DisplayItem(Option<Entity>);
fn display_item_system(
mut commands: Commands,
query: Query<(Entity, &DisplayItem), Changed<DisplayItem>>,
) {
for (entity, display_item) in query.iter() {
commands.entity(entity).clear_children();
if let Some(item_entity) = display_item.0 {
println!("{:?} displaying {:?}", entity, item_entity);
// If there is an item, display it
commands.entity(entity).with_children(|parent| {
parent.spawn(TextBundle::from_section(
format!("{:?}", item_entity),
TextStyle {
font: Default::default(),
font_size: 20.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
));
});
}
}
}