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

Regression: bevy 0.4: Text value update is not rendered when on stage::POST_UPDATE #1102

Closed
Fedcomp opened this issue Dec 20, 2020 · 3 comments
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior

Comments

@Fedcomp
Copy link

Fedcomp commented Dec 20, 2020

bevy 0.4.0
Arch linux with intel drivers

What i did

In bevy 0.4 Text value update is not rendered when was updated on stage::POST_UPDATE. Instead i see the original text i put when created component. Text update render works if system is on stage::UPDATE. I made simple example using default bevy 0.4.0:

cargo add bevy
use bevy::prelude::*;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup_ui.system())
        .add_system_to_stage(stage::POST_UPDATE, text_update_system.system())
        .run();
}

pub fn setup_ui(commands: &mut Commands, asset_server: Res<AssetServer>) {
    commands
        .spawn(CameraUiBundle::default())
        .spawn(TextBundle {
            style: Style {
                align_self: AlignSelf::FlexEnd,
                ..Default::default()
            },
            text: Text {
                value: "Statup text".to_string(),
                font: asset_server.load("FiraSans-Bold.ttf"),
                style: TextStyle {
                    font_size: 30.0,
                    color: Color::BLACK,
                    ..Default::default()
                },
                ..Default::default()
            },
            ..Default::default()
        });
}

pub fn text_update_system(time: Res<Time>, mut query: Query<&mut Text>) {
    for mut text in query.iter_mut() {
        text.value = format!("Updated text. Delta time: {}", time.delta_seconds());
    }
}
cargo run

If i check text/text.value using dbg!() i see correct, updated value, but only original value is rendered.

For example, in bevy 0.3.0 following code kind of works:

use bevy::prelude::*;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup_ui.system())
        .add_system_to_stage(stage::POST_UPDATE, text_update_system.system())
        .run();
}

pub fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands
        .spawn(UiCameraComponents::default())
        .spawn(TextComponents {
            style: Style {
                align_self: AlignSelf::FlexEnd,
                ..Default::default()
            },
            text: Text {
                value: "Statup text".to_string(),
                font: asset_server.load("FiraSans-Bold.ttf"),
                style: TextStyle {
                    font_size: 30.0,
                    color: Color::BLACK,
                    ..Default::default()
                },
                ..Default::default()
            },
            ..Default::default()
        });
}

pub fn text_update_system(time: Res<Time>, mut query: Query<&mut Text>) {
    for mut text in query.iter_mut() {
        text.value = format!("Updated text. Delta time: {}", time.delta_seconds);
    }
}

It has some strange artifacts when rendered, but the text is not default value i set. I hit this issue while attempted to update bevy_rapier from bevy 0.3.0 to 0.4.0.

What i expected to happen

Text should be rendered with updated value at least in the next frame.

What actually happened

Text render only original value and is never updated.

Additional information

I made bevy-0.4 and bevy-0.3 branches in example repository reproducing issue.

I always have warning in my console:

MESA-INTEL: warning: Ivy Bridge Vulkan support is incomplete

But example works on bevy_rapier targeting bevy-0.3.0, and no longer works on nearly same example targeting bevy-0.4.0, so i don't think it's driver issue.

@Moxinilian Moxinilian added C-Bug An unexpected or incorrect behavior A-UI Graphical user interfaces, styles, layouts, and widgets labels Dec 20, 2020
@cart
Copy link
Member

cart commented Dec 20, 2020

I would argue that this isn't a bug. The POST_UPDATE stage exists to respond to "game logic" changes that happen in UPDATE. Changing text is "game logic" and therefore belongs in UPDATE (or a stage between update and POST_UPDATE).

@Fedcomp
Copy link
Author

Fedcomp commented Dec 20, 2020

I initially considered it a bug because it should at least be updated in next frame, but it doesn't?
How do i calculate time spent in update after update and output it as a text?

or a stage between update and POST_UPDATE

For me it looks logical to use POST_UPDATE to calculate time spent in update.
Maybe we need better naming?

@cart
Copy link
Member

cart commented Dec 20, 2020

I initially considered it a bug because it should at least be updated in next frame, but it doesn't?

It doesn't because it relies on Bevy's change detection features, which are very efficient, but as a result require clearing the change state at the end of the frame.

How do i calculate time spent in update after update and output it as a text?

You can either add a new stage between UPDATE and POST_UPDATE (which would allow you to report the time on the same frame), or you can record the time to run UPDATE and queue it up in a resource that is dequeued on the next frame (which would add one frame of lag).

For me it looks logical to use POST_UPDATE to calculate time spent in update.
Maybe we need better naming?

That and/or better docs. If you have any suggestions let me know.

I'm closing this as everything is working as expected, but I'm definitely down to continue discussing ways to improve the situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

3 participants