bevy/crates/bevy_ecs/src/system/commands
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
..
command.rs Have System::run_unsafe return Result. (#19145) 2025-07-03 21:48:09 +00:00
entity_command.rs Avoid early function invocation in EntityEntryCommands (#19978) 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
parallel_scope.rs bevy_ecs/system/commands/ folder docs pass (#18639) 2025-03-31 19:26:58 +00:00