-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsA-ReflectionRuntime information about typesRuntime information about typesC-Code-QualityA section of code that is hard to understand or changeA section of code that is hard to understand or change
Description
Problem
- 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
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. - Components are effectively cloned in a way that bypasses the
Clone
method, which can cause issues with things like ref-counting (used forHandle
).
Possible Solutions
- Give
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.
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsA-ReflectionRuntime information about typesRuntime information about typesC-Code-QualityA section of code that is hard to understand or changeA section of code that is hard to understand or change