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

Children is been added twice #889

Closed
lassade opened this issue Nov 18, 2020 · 2 comments · Fixed by #904
Closed

Children is been added twice #889

lassade opened this issue Nov 18, 2020 · 2 comments · Fixed by #904
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior C-Performance A change motivated by improving speed, memory usage or compile times

Comments

@lassade
Copy link
Contributor

lassade commented Nov 18, 2020

Bevy version
0.3 (commit fae6287)

Operating system & version
Fedora 31

What you did
Spawn a scene with a hierarchy

let mut world = World::default();
let world_builder = &mut world.build();

let components = (
    GlobalTransform::default(),
    Transform::default(),
    Children::default(),
);
world_builder
    .spawn(components.clone())
    .with_children(|builder| {
        builder.spawn(components.clone()).with_children(|builder| {
            builder.spawn(components.clone()).with_children(|builder| {
                builder.spawn(components.clone()).with_children(|builder| {
                    builder.spawn(components.clone()).with_children(|builder| {
                        builder.spawn(components.clone());
                    });
                });
            });
        });
    });

commands.spawn_scene(scenes.add(Scene::new(world)));

What actually happened
Each children will be added twice to it's parent Children component, this causes a massive slowdown caused by the transform_propagate_system witch will then need to update each node hierarchy multiple times.

Additional information
I propose 3 things:

  1. Adding a property ignore to the Children smallvec so it won't get serialized once it get's transformed into a Scene
  2. Fixing WorldBuilder to not insert entities into the Children component
  3. Changing children smallvec to pub(create) and adding a impl Deref<Target = [Entity]> for Children. If the used change this children component the side effects will be devastating
@lassade
Copy link
Contributor Author

lassade commented Nov 18, 2020

Edit:
I didn't spot this error on the latests commit
Nop still there debug_assert didn't catch on release build,

@lassade
Copy link
Contributor Author

lassade commented Nov 19, 2020

Before anything else I recommend making Children.0 and PreviousParent.0 pub(crate).

@cart I found 3 main ways of fixing this issue, but not sure witch one is best:

  1. Check if the entity was already added, if so do nothing (silliest)
  2. impl FromResources and MapEntities for PrevousParent then registry it appropriately (less impact on code structure, but won't fix serialized scenes)
  3. Don't save or map Children entities (break codes that spawns a scene before EVENT and use a entity Children component of that said scene before POST_UPDATE, the big advantage is that scenes will be more robust and easer to set-up)

My main goal is to make the behaviour more consistent and easer to explain: the Children component is a helper component used by the bevy_transform crate, any changes to the hierarchy will only be reflected in the Children component in the next frame or after the POST_UPDATE stage;

For that reason I more inclined to go with 3, (none of theses changes will affect the behaviour of the WorldBuilder.with_children function and friends as it already set Children + PreviousParent)

Opinions?

@Moxinilian Moxinilian added C-Bug An unexpected or incorrect behavior A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times labels Nov 19, 2020
@cart cart closed this as completed in #904 Nov 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior C-Performance A change motivated by improving speed, memory usage or compile times
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants