What problem does this solve or what need does it fill?
Currently when replacing an existing component on an entity via insert, first the OnReplace hook gets fired with the old component value, and then the OnInsert hook gets fired with the new component value. But there's no hook that gets both the old and the new value.
This makes it hard to maintain external datastructures which would benefit from being able to mutate things in them, rather than always removing a thing and then re-adding it right later.
What solution would you like?
A separate OnReinsert hook which would get both the old component and the new component as parameters. This hook would fire only when a component is replaced and never otherwise.
What alternative(s) have you considered?
The existing OnReplace hook could get the new component as an optional parameter always. Then there wouldn't be a need for a new hook. However, as that hook gets fired on both replace and removal, the parameter would have to be Option<T>.
Additional context
Note that this is totally different from OnMutate, which would be fired after a component has changed through a mutable reference. This is about replacing the component through insert().
What problem does this solve or what need does it fill?
Currently when replacing an existing component on an entity via
insert
, first theOnReplace
hook gets fired with the old component value, and then theOnInsert
hook gets fired with the new component value. But there's no hook that gets both the old and the new value.This makes it hard to maintain external datastructures which would benefit from being able to mutate things in them, rather than always removing a thing and then re-adding it right later.
What solution would you like?
A separate
OnReinsert
hook which would get both the old component and the new component as parameters. This hook would fire only when a component is replaced and never otherwise.What alternative(s) have you considered?
The existing
OnReplace
hook could get the new component as an optional parameter always. Then there wouldn't be a need for a new hook. However, as that hook gets fired on both replace and removal, the parameter would have to beOption<T>
.Additional context
Note that this is totally different from
OnMutate
, which would be fired after a component has changed through a mutable reference. This is about replacing the component throughinsert()
.