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

Changed<GlobalTransform> is triggered on each frame for UI nodes #4133

Closed
oceantume opened this issue Mar 7, 2022 · 0 comments
Closed

Changed<GlobalTransform> is triggered on each frame for UI nodes #4133

oceantume opened this issue Mar 7, 2022 · 0 comments
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior D-Trivial Nice and easy! A great choice to get started with Bevy

Comments

@oceantume
Copy link
Contributor

oceantume commented Mar 7, 2022

Bevy version

0.6.1

What you did

Run the following bevy app

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .add_system(do_something_with_node_transform)
        .run();
}

#[derive(Component)]
struct MyNode;

fn setup(mut commands: Commands) {
    commands.spawn_bundle(UiCameraBundle::default());

    commands
        .spawn_bundle(NodeBundle {
            style: Style {
                size: Size::new(Val::Px(150.), Val::Px(60.)),
                margin: Rect::all(Val::Auto),
                ..Default::default()
            },
            color: Color::BLACK.into(),
            ..Default::default()
        });
}

fn do_something_with_node_transform(
    query: Query<&GlobalTransform, Changed<GlobalTransform>>
) {
    for transform in query.iter() {
        bevy::log::info!("Transform changed: {transform:?}");
    }
}

What you expected to happen

The print should only happen when the value of GlobalTransform is actually changed.

What actually happened

A line is printed on every frame, even when the value of GlobalTransform doesn't change.

Additional information

The issue is present when watching both Transform and GlobalTransform.

This is basically the same issue as #3784 but for the GlobalTransform component instead of Node. The fix will be very similar.

@oceantume oceantume added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 7, 2022
@alice-i-cecile alice-i-cecile added A-UI Graphical user interfaces, styles, layouts, and widgets D-Trivial Nice and easy! A great choice to get started with Bevy and removed S-Needs-Triage This issue needs to be labelled labels Mar 7, 2022
@bors bors bot closed this as completed in e41c5c2 Mar 8, 2022
aevyrie pushed a commit to aevyrie/bevy that referenced this issue Jun 7, 2022
# Objective

Fixes bevyengine#4133 

## Solution

Add comparisons to make sure we don't dereference `Mut<>` in the two places where `Transform` is being mutated. `GlobalTransform` implementation already works properly so fixing Transform automatically fixed that as well.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

Fixes bevyengine#4133 

## Solution

Add comparisons to make sure we don't dereference `Mut<>` in the two places where `Transform` is being mutated. `GlobalTransform` implementation already works properly so fixing Transform automatically fixed that as well.
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 D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants