-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Non-overwriting insert commands #2054
Comments
I'm not convinced on the names; bikeshed away. |
I'm not sure this is a good solution to the initial problem. Bundles using the same identifiers, in the worst case for different things, sounds like a nightmare (reminds me of Skyrim mods). Bevy should set standards imho. Things like best-practices bundle authors can follow to create bundles which do not collide with other bundles, or create bundles which can enhance other bundles in a clear way. |
Identifiers will always work on the type level, so I don't think we'll get collisions in the way you're worried about. Rust's name-spacing strategies will work for us already. Reuse of components between plugins is both inevitable and desirable IMO. |
When I originally read this, I thought the issue was that components were getting silently overwritten and therefore, the developer wasn't even aware of the issue. The linked PR and the proposed feature of having a bundle builder api doesn't actually address the question of whether the developer even notices that two bundles insert a conflicting component. I.e. there are two issues:
Is there an existing solution for 1? And if not, how are non-experts supposed to know that the problem even exists? |
Note, |
I like this nomenclature a lot. I personally would like to move towards this. Overall I think this issue should probably be tackled after #2241. |
Is this still on the table? |
Yep: should be straightforward enough, just hasn't been a priority. Feel free to adopt the linked PR or start fresh and ping me for review. |
# 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 <[email protected]> Co-authored-by: Giacomo Stevanato <[email protected]>
What problem does this solve or what need does it fill?
When doing more complex work with bundles, users often end up combining two related bundles, overwriting all values set when they add the second bundle.
What solution would you like?
Add
try_insert_bundle(bundle: impl Bundle)
,try_insert::<C: Component>(component: Component)
commands.These act like their non-try versions, but do not overwrite existing components of the same type.
As part of the same PR, include
try_insert_resource
andtry_insert_local_resource
for consistency (and related uses).What alternative(s) have you considered?
Better bundle merging tools.
Make this the default behaviour, and instead change the current behavior to something like
force_insert
.Additional context
Handling the results of these commands relates to #2004, and should probably be left as part of that.
The text was updated successfully, but these errors were encountered: