-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Use component lifecycle hooks to make Parent
+ Children
hierarchy code simpler and more robust
#12235
Comments
Is this just using hooks for cleanup? Like removing dangling, despawn recursive, etc? |
Yeah, I think that's about all we'll be able to do currently. |
If we don't allow users to mutably access the components directly we can enforce an always up to date hierarchy by only allowing commands to modify it. Although this would be an access pattern that I don't believe bevy currently uses anywhere. |
That's what I do for aery. Private |
I did most of the work for this a while ago as I was testing the hooks PR. |
Awesome, thank you @irate-devil :) And yeah, ironing out the kinks of the component hooks API is a big part of why I'm keen to do this. |
Doing this is going to require making |
EDIT: Tabbed over to the wrong issue! |
What is the point of using hooks if we restrict access to commands? Can't we just do the cleanup in the commands? |
The fix for this has been marked for 0.16, probably should do the same here. |
What problem does this solve or what need does it fill?
bevy_hierarchy
's internals are complex, performance-critical, and have panicking unsafe code in them.The core reason for this is that we cannot let the graph become invalid: this leads to wasted work, subtle bugs and huge amounts of user frustration. And because we use
unsafe
code internally that relies on the assumption of validity for soundness, this can become a soundness problem.They're painful to maintain, and nearly impossible to replicate externally for other hierarchy-like code that wants to uphold these same variants.
What solution would you like?
#10756 adds component lifecycle hooks: operations that take effect when components are added or removed.
We should replace the existing complex code in
bevy_hierarchy
with this idiom, being sure to benchmark and optimize performance.What alternative(s) have you considered?
We could wait until the fabled day that relations (#3742) finally gets shipped.
Additional context
This has been widely anticipated as one of the key benefits of that PR: I'm recording it here to make sure we don't forget (and can coordinate work).
While the user-facing API is also pretty gnarly and inconsistent, I'd like to leave that for future work to make sure that the correctness-sensitive internals get the review attention it needs.
The text was updated successfully, but these errors were encountered: