Dynamic collections of components (of the same type) logically grouped/coupled #10041
-
I want to know what's the best way to handle dynamic collections of components that are from the same Rust type. Example so we can talk in the same terms: I'm writing a multiplayer snake clone game. In this game, I currently use
But if I make I thought about putting each segment as a component, and mark it with some player tag and body number. Then I'd be able to query all the segments, group them, sort them and do the collection/queue logic. The thing is that this approach is not comfortable, it feels hacky and probably hard to maintain I've also seen other people use What would you do? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
struct Snake {
segments: VecDeque<Entity>,
} You need each of the segments to be their own entity, so then they're rendered properly :) With this solution, you can record that and also have multiple snakes. Just be careful not to desynchronize this list and the spawning / despawning! Custom commands can help a lot there. |
Beta Was this translation helpful? Give feedback.
You need each of the segments to be their own entity, so then they're rendered properly :) With this solution, you can record that and also have multiple snakes. Just be careful not to desynchronize this list and the spawning / despawning! Custom commands can help a lot there.