Skip to content

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

Closed

Description

@ickshonpe

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.

Activity

  1. added
    C-BugAn unexpected or incorrect behavior
    S-Needs-TriageThis issue needs to be labelled
    on Aug 20, 2023
  2. 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>`[/+] on Aug 20, 2023
  3. added
    A-TransformTranslations, rotations and scales
    and removed
    S-Needs-TriageThis issue needs to be labelled
    on Aug 21, 2023
  4. added a commit that references this issue on Aug 28, 2023
    aa20565
  5. added a commit that references this issue on Jan 9, 2024
    cbd2997
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-TransformTranslations, rotations and scalesC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions