Soft child insertion (for example, try_add_child)
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
```
Encountered an error in command `::add_related:
:{{closure}} as bevy_ecs::error::command_handling::CommandWithEntity>>::with_entity::{{closure}}`: The entity with ID 986v5 does not exist (enable `track_location` feature for more details)
```
Which crashes the app.
## What solution would you like?
A function like `try_insert` compared to `insert` where it logs a warning instead of panicing.
## What alternative(s) have you considered?
I'm currently a custom command someone provided on the Discord server, but thought it might be benefitial for others if something like that existed on the official repo. Here's what I'm currently using:
```
commands.queue(move |world: &mut World| {
let Ok(mut ec) = world.get_entity_mut(sprite_entity) else {
return;
};
ec.add_child((
// child here
));
});
```
Contributor guide
Research direction
Start by reading the existing EntityCommands add_related and insert behavior, along with the custom World command shown in the issue. Define the soft-insertion behavior around missing entities, then verify that it warns instead of panicking while preserving normal child insertion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100