-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
I'm confused by the docs for on_replace.
https://docs.rs/bevy/latest/bevy/ecs/relationship/trait.Relationship.html#method.on_replace
Register a ComponentHook that will be run when this component is about to be dropped, such as being replaced (with .insert) or removed.
So I asked in Discord, #ecs
Can I expect it to be run whenever a component is removed, regardless of whether it's being replaced?
I came to this because I'm implementing a custom Relationship, and I saw that trait Relationship provides
on_insert
andon_replace
. So ison_remove
not needed, ason_replace
runs anyway, regardless of whether the component is actually being replaced?
Tim kindly answered
Yes, it is run when the component is removed, and yes the naming here is very confusing
As far as I can tell the actual on_remove hook is useless for any kind of bookeeping
So, I think the docs for this method should be improved so they're less confusing. I still don't understand what it's for / how it works in enough detail to propose better docs.
An alternative would be to choose a better name for the method. Perhaps on_removing
would be clearer, as it expresses "yes it's being removed" and "the removal is kind of in-progress, so you can still get at stuff"