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

sync_simple_transforms only checks for removed parents and doesn't filter for Without<Parent> #9517

Closed
ickshonpe opened this issue Aug 20, 2023 · 0 comments · Fixed by #9518
Labels
A-Transform Translations, rotations and scales C-Bug An unexpected or incorrect behavior

Comments

@ickshonpe
Copy link
Contributor

ickshonpe commented Aug 20, 2023

Bevy version

Bevy main 3aad5c6

What you did

use bevy::prelude::*;

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

fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
    commands.spawn(SpriteBundle {
        sprite: Sprite {
            color: Color::WHITE,
            custom_size: Some(Vec2::splat(100.)),
            ..Default::default()
        },
        transform: Transform::from_translation(50. * Vec3::ONE),
        ..Default::default()
    })
    .with_children(|commands| {
        commands.spawn(SpriteBundle { 
            sprite: Sprite {
                color: Color::RED,
                custom_size: Some(Vec2::splat(110.)),
                ..Default::default()
            },
            transform: Transform::from_translation(50. * Vec3::ONE),
            ..Default::default()
        });
    });
}

fn remove_and_set_parent(
    input: Res<Input<KeyCode>>,
    mut commands: Commands,
    query: Query<(Entity, &Parent), With<Sprite>>,
) { 
    if input.just_pressed(KeyCode::Space) {
        for (e, p) in query.iter() {
            commands.entity(e).remove_parent();
            commands.entity(e).set_parent(p.get());
        }
    }
}

run it and you get:

transform_bug_1

after pressing space:

transform_bug_2

What went wrong

sync_simple_transforms only checks for removed parents and doesn't filter for Without<Parent>, so it overwrites the GlobalTransform of non-orphan entities that removed and then added a parent since the last update.

@ickshonpe ickshonpe added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Aug 20, 2023
@ickshonpe ickshonpe changed the title sync_simple_transforms only checks for removed parents and doesn't filter for `Without<Parent> sync_simple_transforms only checks for removed parents and doesn't filter for Without<Parent> Aug 20, 2023
@alice-i-cecile alice-i-cecile added A-Transform Translations, rotations and scales and removed S-Needs-Triage This issue needs to be labelled labels Aug 21, 2023
github-merge-queue bot pushed a commit that referenced this issue Aug 28, 2023
…tities query (#9518)

# Objective

`sync_simple_transforms` only checks for removed parents and doesn't
filter for `Without<Parent>`, so it overwrites the `GlobalTransform` of
non-orphan entities that were orphaned and then reparented since the
last update.

Introduced by #7264

## Solution

Filter for `Without<Parent>`.

Fixes #9517, #9492

## Changelog

`sync_simple_transforms`:
* Added a `Without<Parent>` filter to the orphaned entities query.
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this issue Jan 9, 2024
…tities query (bevyengine#9518)

# Objective

`sync_simple_transforms` only checks for removed parents and doesn't
filter for `Without<Parent>`, so it overwrites the `GlobalTransform` of
non-orphan entities that were orphaned and then reparented since the
last update.

Introduced by bevyengine#7264

## Solution

Filter for `Without<Parent>`.

Fixes bevyengine#9517, bevyengine#9492

## Changelog

`sync_simple_transforms`:
* Added a `Without<Parent>` filter to the orphaned entities query.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Transform Translations, rotations and scales C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants