bevy/crates/bevy_ecs/src/storage
Jeff Petkau b2529bf100
feat: add insert_if_new (#14397) (#14646)
# Objective

Often there are reasons to insert some components (e.g. Transform)
separately from the rest of a bundle (e.g. PbrBundle). However `insert`
overwrites existing components, making this difficult.

See also issue #14397

Fixes #2054.

## Solution

This PR adds the method `insert_if_new` to EntityMut and Commands, which
is the same as `insert` except that the old component is kept in case of
conflicts.

It also renames some internal enums (from `ComponentStatus::Mutated` to
`Existing`), to reflect the possible change in meaning.

## Testing

*Did you test these changes? If so, how?*

Added basic unit tests; used the new behavior in my project.

*Are there any parts that need more testing?*

There should be a test that the change time isn't set if a component is
not overwritten; I wasn't sure how to write a test for that case.

*How can other people (reviewers) test your changes? Is there anything
specific they need to know?*

`cargo test` in the bevy_ecs project.

*If relevant, what platforms did you test these changes on, and are
there any important ones you can't test?*

Only tested on Windows, but it doesn't touch anything platform-specific.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com>
2024-08-15 20:31:41 +00:00
..
blob_vec.rs feat: add insert_if_new (#14397) (#14646) 2024-08-15 20:31:41 +00:00
mod.rs Improve doc formatting. (#9840) 2023-09-18 19:43:56 +00:00
resource.rs Track source location in change detection (#14034) 2024-07-30 12:02:38 +00:00
sparse_set.rs Track source location in change detection (#14034) 2024-07-30 12:02:38 +00:00
table.rs feat: add insert_if_new (#14397) (#14646) 2024-08-15 20:31:41 +00:00