-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
There is no viable alternative to HierarchyEvent
#19019
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
Comments
Can you use observers here? You should have all of the same information available: the removed data from the components is available. |
I suppose I could. I'm assuming that's basically what Jondolf suggested in their comment. It feels a bit heavy though, since as I understand it (please correct me if I'm wrong), this would be a separate entity with the sole purpose of reacting to Is there a particular reason the event API was removed? It's a much more natural interface when immediate execution is a not an issue. It'd be so much more useful as a Edit: Maybe the middle-ground solution here is an abstraction layer that uses observers to generate relation events, so it could be opt-in by the user, but without requiring the user to re-implement the pattern for every relation. |
This would be two entities for any hierarachy event, regardless of which entity is getting changed. While observers can watch only a subset of entities, by default they watch for any entity.
From my recollection, this was "let's try and reduce duplicate tools and passive overhead".
This is a reasonable idea, but I still suspect that there was a miscommunication about what's entailed with the observer pattern. Do you mean "for every new type of relation (analagous to |
Yes. For example, in my project, I have an inventory system. I need to know when an item is inserted or removed from the inventory in order to update some state. Previously, I could do this by having an But now, with relations, I would need to have two observers to monitor In my mind, it would be a lot more straightforward to just "map" the Alternatively, I could have more observers to detect changes to With generic relations events, I could see mapping between any Another possible solution is to add a new Edit: Also, if I understand correctly, it wouldn't be just 2 observers per relation. It's 2 observer per use of relation. So for example, if I have three independent game features (e.g. plugins), all monitoring hierarchy changes, I would need 6 observers? |
Correct; that's what I'm saying.
Something like this is my preference: there's clearly an abstraction missing here in some form; you shouldn't have to write two distinct observers for the same logic.
Can you say more about why? Are you worried about memory overhead? Inspector pollution? Visceral ick? All of those are valid, but I want to make sure I understand the objections clearly. The fact that observers are implemented via entities is largely a convenience and implementation detail. |
It's a bit all of the above.
All this makes observers feel like second-class citizens to me. Which is fine, but I would argue detecting relation changes is such a critical part of systems development that it deserves a first-class API, like events. |
Thanks for the explanation! I'm looking at an overhaul of observers this cycle, and this perspective was really helpful to me.
FWIW, I'm intending to do this for resources too :) |
Thanks for the explanation and follow up! :)
If we're going the route of putting everything on entities, it makes a lot more sense to me! Then if we just have a |
What problem does this solve or what need does it fill?
With 0.16, it looks like
HierarchyEvent
was removed. Prior to 0.16,HierarchyEvent
was the only way to reliably detect specific changes to a hierarchy.I realize we have
RemovedComponents
. The problem with it is that it only tells you from which entities it was removed; it doesn't give you the component data.So if I listen to
RemovedComponent<ChildOf>
, I won't know which parent the entity was removed from. I could listen toChanged<Children>
, but what ifChildren
gets removed? Then I'd have to also listen toRemovedComponents<Children>
... and I'd still have the same issue asRemovedComponent<ChildOf>
.What solution would you like?
Either a
RelationEvent
to detect when relations change, or a way to access removed component data.What alternative(s) have you considered?
Alternatively, I could use component hooks, but I believe having the ability to know when a specific relationship has ended between which exact entities at a system level is critical.
Additional context
This has also been brought up before:
#13925 (comment)
#17398 (comment)
The text was updated successfully, but these errors were encountered: