bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.42k stars 3.5k forks source link

Add `Added<Entity>` to bevy #8924

Open MalekiRe opened 1 year ago

MalekiRe commented 1 year ago

What problem does this solve or what need does it fill?

Getting whenever an entity is added generally, without it requiring a specific component be added is useful when trying to sync entities over a network.

What solution would you like?

Add the Added<Entity> for entities

What alternative(s) have you considered?

Iterating through the world and keeping track of what entities existed before.

Additional context

Any other information you would like to add such as related previous work, screenshots, benchmarks, etc.

image

Adamkob12 commented 1 year ago

I doubt this is possible, and if it is - it looks unfeasible. From what I understand by reading some source code and documentation, bevy only keeps track of the time components have been added / changed. Entities are just compact pointers to multiple components, and they don't have much "inherit value". The source code is very complex but from what I understood there is a central data structure that neatly keeps track of the components (It even changes the value of the Entity itself for optimization- making querying new entities even harder) but it doesn't consider the Entity itself. I would use a temporary Component, like ToSync and add it to entities that have not been "synced" yet, and when they are, remove it. I'm somewhat new to bevy, so take this with a grain of salt.