amethyst/legion

Tracking issue: support change detection for delete entities & components

AThilenius opened this issue · 2 comments

For the hierarchy implementation I need a way to detect both deleted entities and components (I don't think I need to disambiguate however, just when any Parent or entity that had a Parent is deleted).

The ideal case would be to have a separate deleted filter that would also give me that last set Component value. I could see this being problematic in terms of leaking memory however.

Tagging @jaynus here too.

Would what is outlined in #15 be enough for this, or do you need to be able to read the Parent component before the entity is removed?

Hmmm. Yeah this is a tricky one. Ideal case is to iterate through (or receive events for) entities with a query like: 'read the PreviousParent components for any deleted entity with a Parent and PreviousParent, or any entity that has a deleted Parent component).

The more I think of it though, the more can-of-worms this gets. If you have an API to provide component data after it has been 'deleted', then the potential to leak memory seems significant. All the user has to do is forget to consume all the events.

Another way to work around this for my use-case (I think Unity ECS might do this too, actually) would be:

  • Collect a set of 'known' entity IDs by querying for all Children components.
  • Iterate through all Parent and PreviousParent components to compare what was removed from the hierarchy.

I don't think that would require remove events at all but might be more costly.