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

Transform not propagated for child due to delay of inserting Children #1807

Closed
jakobhellermann opened this issue Apr 3, 2021 · 3 comments
Closed
Labels
A-Hierarchy Parent-child entity hierarchies A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior

Comments

@jakobhellermann
Copy link
Contributor

In the following code snippet, the 1.5 scale is not applied to the scene:

fn setup(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    mut scene_spawner: ResMut<SceneSpawner>,
) {
    let scene_holder = commands
        .spawn()
        .insert(GlobalTransform::default())
        .insert(Transform::from_scale(Vec3::splat(1.5)))
        .insert(Holder)
        .id();

    let scene_handle = asset_server.load("models/AlienCake/cakeBirthday.glb#Scene0");
    scene_spawner.spawn_as_child(scene_handle, scene_holder);
}

The transform_propagate_system only runs if either the parent is Changed or the child is Changed.
However, in this case the order of operations is

  1. scene_holder 0v0 is spawned (and is Changed for one frame)
  2. later the scene is spawned (e.g. 0v3)
    0v3 is Changed for one frame.
    A Parent(0v0) component is scheduled to be added via commands.
  3. parent_update_system is run, but the insert Children command is not yet processed
  4. transform_propagate_system is run. 0v3 is still Changed, but since 0v0 has no children yet nothing happens.
  5. Next frame. 0v0 now has Children([0v3]).
  6. parent_update_system is run, nothing to be done
  7. transform_propagate_system is run. This time there are children for 0v0, but 0v3 is not changed anymore, so nothing happens.

The problem is "fixed" by either adding a

fn force_transform_change(mut q: Query<&mut Transform>) {
    for mut t in q.iter_mut() { t.deref_mut(); }
}

or removing the Changed from transform_propagate_system.

It is also fixed by adding .with_children(|_| {}) to the scene_holder, because then the parent_update_system can simply insert to the existing children which works without delay.

A simpler repro is here.

@jakobhellermann
Copy link
Contributor Author

jakobhellermann commented Apr 3, 2021

The repro can be fixed by using
commands.entity(parent).push_children(&[child]) instead of .insert(Parent(parent)).

@jakobhellermann jakobhellermann changed the title Transform not propagated for child if parent had no Children Transform not propagated for child due to delay of inserting Children Apr 3, 2021
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use and removed C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Apr 3, 2021
@alice-i-cecile alice-i-cecile added the A-Hierarchy Parent-child entity hierarchies label Apr 4, 2022
@james7132
Copy link
Member

Is this still an issue after #4197?

@nicopap
Copy link
Contributor

nicopap commented Jan 31, 2023

I can confirm this is fixed with #4197, using the repro linked earlier.

@nicopap nicopap closed this as completed Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Hierarchy Parent-child entity hierarchies 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

4 participants