You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ReflectComponent::copy_component allows users to copy any arbitrary component data to different entities, and across worlds, as long as it is reflect-able.
Neither Reflect nor Component has a Clone 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.
Components are effectively cloned in a way that bypasses the Clone method, which can cause issues with things like ref-counting (used for Handle).
Possible Solutions
Give Reflect and/or Component a Clone 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.
Problem
ReflectnorComponenthas aClonebound, 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.Clonemethod, which can cause issues with things like ref-counting (used forHandle).Possible Solutions
Reflectand/orComponentaClonebound. 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
Clonebound.Use the appropriate
Clonemethods when they exist.Leave the existing behavior in place, and very clearly document what's going on and how to use it safely.