Skip to content

Relationship::on_replace docs are confusing #20188

@SteveAlexander

Description

@SteveAlexander

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 and on_replace. So is on_remove not needed, as on_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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-DocsAn addition or correction to our documentationS-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions