-
-
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
Reflection allows users to clone arbitrary reflected components, but Reflect does not have a Clone bound #3372
Comments
I believe this copy would happen based on creating a new default, then reflecting the old onto the new, not be some extremely bad UB |
@mockersf points out that this If we implement both This does however make me increasingly convinced that we should have either |
bevy/crates/bevy_ecs/src/reflect.rs Line 81 in ed9d45f
bevy/crates/bevy_ecs/src/world/mod.rs Lines 1171 to 1175 in ed9d45f
|
Yes, which is a nice feature (although I still like As |
Yeah, this is just an ecosystem-wide "problem". Closing. |
Problem
Reflect
norComponent
has aClone
bound, and so we can sneakily clone components that are not expecting to be cloned. I'm pretty sure this is ultimately done by just copying their raw memory.Clone
method, which can cause issues with things like ref-counting (used forHandle
).Possible Solutions
Reflect
and/orComponent
aClone
bound. This fixes problem 2, but not problem 3, and may be painful in niche use cases (although I have not seen any concrete use cases for components that cannot be cloned raised, see Command to clone entities #1515).Furthermore, not all fields of a component should be reflected. Cloning components with some cloneable field and defaulting the others is a reasonable strategy here, but does not permit a
Clone
bound.Use the appropriate
Clone
methods when they exist.Leave the existing behavior in place, and very clearly document what's going on and how to use it safely.
The text was updated successfully, but these errors were encountered: