Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding children to UI Text makes it disappear #17551

Open
eero-lehtinen opened this issue Jan 26, 2025 · 2 comments
Open

Adding children to UI Text makes it disappear #17551

eero-lehtinen opened this issue Jan 26, 2025 · 2 comments
Labels
C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled

Comments

@eero-lehtinen
Copy link
Contributor

Bevy version

main (1c765c9)

What you did

When you add a Node as a child of a Text, the text is not rendered at all.

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn(Camera2d);
    commands
        .spawn((
            Text::new("hello\nbevy!"),
            TextFont {
                font_size: 67.0,
                ..default()
            },
            Node {
                left: Val::Px(20.),
                ..default()
            },
        ))
        // Adding this makes the above text disappear
        .with_child((
            Node {
                width: Val::Px(40.),
                height: Val::Px(40.),
                ..default()
            },
            BackgroundColor(Color::WHITE.with_alpha(0.5)),
        ));
}

What went wrong

I would expect the text to remain visible.

The entity with Text still seems to contribute to the layout, but it doesn't show up. It seems that Text is somehow hardcoded to only allow TextSpan children and breaks with anything else.

I ran into this while trying to make pseudo outlines by drawing multiple texts on top of each other in the hierarchy, but the parent text just doesn't show up.

@eero-lehtinen eero-lehtinen added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jan 26, 2025
@ickshonpe
Copy link
Contributor

ickshonpe commented Jan 27, 2025

Text should always be leaf nodes imo.

It's easier to implement pseudo-outlines using an extraction system. Should be straightforward to repurpose the changes from #17559.

@eero-lehtinen
Copy link
Contributor Author

eero-lehtinen commented Jan 27, 2025

I think it would be convenient to sometimes have extra nodes that are positioned relative to text, e.g. a poison icon attached to a poison number.

Is there any reason this needs to work like this? Why not just display non-leaf text?

But yeah you can work around this by having another parent node for the text and add the secondary text as a sibling with absolute positioning.

It's easier to implement pseudo-outlines using an extraction system. Should be straightforward to repurpose the changes from #17559.

Thanks. I'll look into that. Extraction doesn't seem very approachable for user code but good to know. Also I'm using another font for the outline so that code won't work directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled
Projects
None yet
Development

No branches or pull requests

2 participants