How to model attachments to entities? #7562
Unanswered
Mandragorian
asked this question in
Q&A
Replies: 1 comment
-
Not to worry, Bevy already has ECS support for parent-child relationships. Just spawn your attachments as children of a rocket entity, and then you can easily query both the parent and each of its children by following this: https://bevy-cheatbook.github.io/features/parent-child.html |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to model the following problem:
Say I am creating a Rocket-building application. I want to have a rocket, and various attachments that players can add on the rocket. For example thrusters, sensors, fins etc.
My idea for now was to have a components called
Attachments
which has aVec
ofEntity
s. Then I could iterate over all the entities in theVec
and do what they are supposed to do.But of course then I realised that even if I have that
Vec
just getting the entities won't really help me, since (I think) I can't get their components and do anything useful with them. Should I theVec
of attachments be an enum of all possible attachments, which are not themselves entities, but are structs that implement each attachment's functionality?I am not sure if that is abusing how an ECS should function. I hoped that the functionality of each attachment would be implemented as a component of an entity.
Beta Was this translation helpful? Give feedback.
All reactions