bevy/crates/bevy_ecs/src/relationship
JaySpruce eb6afd26a1
Avoid early function invocation in EntityEntryCommands (#19978)
## Objective

Fixes #19884.

## Solution

- Add an internal entity command `insert_with`, which takes a function
returning a component and checks if the component would actually be
inserted before invoking the function.
- Add the same check to `insert_from_world`, since it's a similar
situation.
- Update the `or_insert_with`, `or_try_insert_with`, and `or_default`
methods on `EntityEntryCommands` to use the new command.

Since the function/closure returning the component now needs to be sent
into the command (rather than being invoked before the command is
created), the function now has `Send + 'static` bounds. Pretty typical
for command stuff, but I don't know how/if it'll affect existing users.

---------

Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com>
2025-07-07 20:02:55 +00:00
..
mod.rs Avoid early function invocation in EntityEntryCommands (#19978) 2025-07-07 20:02:55 +00:00
related_methods.rs EntityWorldMut methods do not automatically overwrite Relationship components (#19601) 2025-06-22 00:22:05 +00:00
relationship_query.rs Let query items borrow from query state to avoid needing to clone (#15396) 2025-06-16 21:05:41 +00:00
relationship_source_collection.rs improved the entity_index_map unit test (#19936) 2025-07-03 20:36:09 +00:00