bevy/crates/bevy_ecs/src/system
rudderbucky 2da8d17a44
Add try_despawn methods to World/Commands (#15480)
# Objective

Fixes #14511.

`despawn` allows you to remove entities from the world. However, if the
entity does not exist, it emits a warning. This may not be intended
behavior for many users who have use cases where they need to call
`despawn` regardless of if the entity actually exists (see the issue),
or don't care in general if the entity already doesn't exist.

(Also trying to gauge interest on if this feature makes sense, I'd
personally love to have it, but I could see arguments that this might be
a footgun. Just trying to help here 😄 If there's no contention I could
also implement this for `despawn_recursive` and `despawn_descendants` in
the same PR)

## Solution

Add `try_despawn`, `try_despawn_recursive` and
`try_despawn_descendants`.

Modify `World::despawn_with_caller` to also take in a `warn` boolean
argument, which is then considered when logging the warning. Set
`log_warning` to `true` in the case of `despawn`, and `false` in the
case of `try_despawn`.

## Testing

Ran `cargo run -p ci` on macOS, it seemed fine.
2024-10-03 16:21:05 +00:00
..
commands Add try_despawn methods to World/Commands (#15480) 2024-10-03 16:21:05 +00:00
adapter_system.rs Better warnings about invalid parameters (#15500) 2024-10-03 13:16:55 +00:00
builder.rs Reorganize SystemParamBuilder docs and examples. (#15102) 2024-09-30 16:59:52 +00:00
combinator.rs Better warnings about invalid parameters (#15500) 2024-10-03 13:16:55 +00:00
exclusive_function_system.rs Better warnings about invalid parameters (#15500) 2024-10-03 13:16:55 +00:00
exclusive_system_param.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
function_system.rs Better warnings about invalid parameters (#15500) 2024-10-03 13:16:55 +00:00
input.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
mod.rs Reorganize SystemParamBuilder docs and examples. (#15102) 2024-09-30 16:59:52 +00:00
observer_system.rs fix observer docs (#15415) 2024-09-25 00:05:33 +00:00
query.rs Populated (query) system param (#15488) 2024-09-30 18:05:00 +00:00
system_name.rs System param validation for observers, system registry and run once (#15526) 2024-09-30 01:00:39 +00:00
system_param.rs Better warnings about invalid parameters (#15500) 2024-10-03 13:16:55 +00:00
system_registry.rs Make SystemIdMarker reflect-able (#15556) 2024-10-01 22:46:44 +00:00
system.rs Better warnings about invalid parameters (#15500) 2024-10-03 13:16:55 +00:00