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

Add hierarchy example #565

Merged
merged 4 commits into from
Oct 1, 2020
Merged

Add hierarchy example #565

merged 4 commits into from
Oct 1, 2020

Conversation

jngbsn
Copy link
Contributor

@jngbsn jngbsn commented Sep 24, 2020

Fixes #513

@Moxinilian Moxinilian added A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible C-Examples An addition or correction to our examples labels Sep 24, 2020
examples/ecs/hierarchy.rs Outdated Show resolved Hide resolved
commands.despawn(child);
}

if time.seconds_since_startup >= 4.0 && children.len() == 2 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To better illustrate the "despawn recursive" behavior, it might be better to despawn the "parent" entity

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point! Although I do like the idea of showing that despawn_recursive also takes care of cleaning up the parent's children. Maybe keep this one in and add another step where it despawns the parent afterwards? As well as some clearer comments to go with it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that we aren't directly illustrating despawn_recursive if it doesn't despawn multiple entities. If we leave the current line as-is, it only despawns one entity. If after the fact we despawn the parent recursively, that also only despawns one entity because there will be no children left.

I think this has my preference:

        // To demonstrate removing children, we'll start to remove the children after a couple of seconds
        if time.seconds_since_startup >= 2.0 && children.len() == 3 {
            // Using .despawn() on an entity does not remove it from its parent's list of children!
            // It must be done manually if using .despawn()
            // NOTE: this is a bug. eventually Bevy will update the children list automatically
            let child = children.pop().unwrap();
            commands.despawn(child);
        }

        if time.seconds_since_startup >= 4.0 {
            // Alternatively, you can use .despawn_recursive()
            // This will remove the entity from its parent's list of children, as well as despawn
            // any children the entity has.
            commands.despawn_recursive(parent);
        }

I added a "note" that explains that the "children list maintenance" will eventually be fixed

@cart
Copy link
Member

cart commented Sep 26, 2020

Clippy error isn't your fault here. Its a new nightly clippy rule. Should be fixed once we merge this: #577

@jngbsn
Copy link
Contributor Author

jngbsn commented Sep 26, 2020

Good to know, I did happen to have a legitimate error I missed, but that should be fixed.

@cart cart changed the base branch from master to pr-merge-helper September 26, 2020 18:07
@cart cart changed the base branch from pr-merge-helper to master September 26, 2020 18:07
@cart
Copy link
Member

cart commented Oct 1, 2020

I just force-pushed a rebase on master. I tried coming up with a better workflow for forcing a new CI build from latest master, but sadly I couldn't (without adding PR orchestrator github actions).

@cart cart merged commit 8e87646 into bevyengine:master Oct 1, 2020
mrk-its pushed a commit to mrk-its/bevy that referenced this pull request Oct 6, 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-Examples An addition or correction to our examples C-Feature A new feature, making something new possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Getting an entity's children
3 participants