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

Getting an entity's children #513

Closed
Bauxitedev opened this issue Sep 19, 2020 · 8 comments · Fixed by #565
Closed

Getting an entity's children #513

Bauxitedev opened this issue Sep 19, 2020 · 8 comments · Fixed by #565
Labels
A-ECS Entities, components, systems, and events C-Docs An addition or correction to our documentation D-Trivial Nice and easy! A great choice to get started with Bevy

Comments

@Bauxitedev
Copy link

Bauxitedev commented Sep 19, 2020

I'm writing a simple test game with Bevy, and I'm using the parent/child structure to add a child entity containing SpriteComponents to the player entity. Now I have a system that takes the Player entity and updates it. However, when I want to update the sprite from this system, there appears to be no way to do this, since I cannot access the child entity holding the sprite components. It would be nice to have a get_children function to iterate over all children of a certain entity.

I could add the SpriteComponents directly to the player, but this seems very messy, since it'll pollute the player's components with the components of the sprite (components like Material, Draw, MainPass, RenderPipelines, etc should be encapsulated in a child entity).

@Bauxitedev Bauxitedev changed the title Getting an entity's childen Getting an entity's children Sep 19, 2020
@Moxinilian
Copy link
Member

This feature already exists in the engine: simply acquire the Children component of the parent entity (added automatically by the engine) to access a list of all its children.

However, this should be better documented. Maybe a general example on hierarchies could help?

@Moxinilian Moxinilian added C-Docs An addition or correction to our documentation A-ECS Entities, components, systems, and events labels Sep 19, 2020
@Bauxitedev
Copy link
Author

@Moxinilian That did the trick, thanks! This would be a great thing to document, indeed.

@cart
Copy link
Member

cart commented Sep 20, 2020

Agreed. Lets consider a new extended "hierarchy" example the exit criteria for this issue.

@cart cart added the D-Trivial Nice and easy! A great choice to get started with Bevy label Sep 23, 2020
@cart cart closed this as completed in #565 Oct 1, 2020
@nablabla
Copy link

This feature already exists in the engine: simply acquire the Children component of the parent entity (added automatically by the engine) to access a list of all its children.

However, this should be better documented. Maybe a general example on hierarchies could help?

Is there documentation on this now? How do I access the Component Children of an entity?

@Moxinilian
Copy link
Member

Is there documentation on this now? How do I access the Component Children of an entity?

@nablabla this example should help: https://github.com/bevyengine/bevy/blob/main/examples/ecs/hierarchy.rs

@nablabla
Copy link

nablabla commented Oct 7, 2023

@Moxinilian not really, I have some entity that I just created, now I want to change the camera layer of it and all its children recursively. The example makes a query of existing entities. But I want to access an entity that I just created before I return from the function where I create them.
So I want to write a function that moves an entity and all of its children to another camera layer, sometimes I have a big tree of entities. I could carry around an argument through all my creation functions but that seems excessively messy to me.

@Moxinilian
Copy link
Member

If you move an entity from one parent to another, the children will follow as they are attached in a tree-like fashion. Would getting the entity ID of your newly created entity and attaching it to the entity of interest to you work?

@nablabla
Copy link

ne, because "moving an entity to another camera layer" is not really moving it anywhere but rather adding a frame bundle to it which does that. And it also makes sense, that the engine does not treat this recursively. Because I think some one might want to have an entity with children distributed on multiple layers.
This limitation of bevy makes it difficult to write factories or decorator (if I understand the pattern correctly)

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-Docs An addition or correction to our documentation D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants