0

I'm using Bevy 0.11, which has a default font. Unfortunately I'm struggling to get the text to actually show up. I have confirmed that my system is running and that the dep I'm using is actually 0.11.

Relevant code:

fn lobby_startup(mut commands: Commands) {
    commands.spawn(Camera3dBundle::default());

    // All this is just for spawning centered text.
    commands
        .spawn(NodeBundle {
            style: Style {
                width: Val::Percent(100.0),
                height: Val::Percent(100.0),
                position_type: PositionType::Absolute,
                justify_content: JustifyContent::Center,
                align_items: AlignItems::FlexEnd,
                ..default()
            },
            background_color: Color::rgb(0.43, 0.40, 0.38).into(),
            ..default()
        })
        .with_children(|parent| {
            parent
                .spawn(TextBundle {
                    style: Style {
                        align_self: AlignSelf::Center,
                        justify_content: JustifyContent::Center,
                        ..default()
                    },
                    text: Text::from_section(
                        "Entering lobby...",
                        TextStyle {
                            font: Default::default(),
                            font_size: 96.,
                            color: Color::BLACK,
                        },
                    ),
                    ..default()
                })
                .insert(LobbyText);
        })
        .insert(LobbyUI);
}

Full repro possible like this:

git@github.com:banool/plane.git
cd plane
git checkout 48b6318602a7deefeacfa2648f22b0e77ffd5611
cargo run
Daniel Porteous
  • 5,536
  • 3
  • 25
  • 44
  • Interestingly other systems later on fail if they try to query LobbyText, so something tells me the entity isn't being spawned / the component attached correctly. – Daniel Porteous Jul 21 '23 at 01:53

1 Answers1

1

I had similar problem. font: Default.default() didn't work for me. Try to load font as resource.

  1. Add new parameter to loby_startup function: asset_server: Res<AssetServer>
fn lobby_startup(mut commands: Commands, asset_server: Res<AssetServer>)
  1. change TextStyle, font property

    text: Text::from_section(
       "Entering lobby...",
        TextStyle {
           font: asset_server.load("path_to_some_ttf_font"),
           font_size: 96.,
            color: Color::BLACK,
        },
    ),
    ..default()
Nenad J.
  • 331
  • 2
  • 8