-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Change Detection as Components / Opt-in or opt-out of Change Detection #4882
Copy link
Copy link
Open
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-Code-QualityA section of code that is hard to understand or changeA section of code that is hard to understand or changeC-PerformanceA change motivated by improving speed, memory usage or compile timesA change motivated by improving speed, memory usage or compile timesS-Needs-Design-DocThis issue or PR is particularly complex, and needs an approved design doc before it can be mergedThis issue or PR is particularly complex, and needs an approved design doc before it can be mergedX-Needs-SMEThis type of work requires an SME to approve it.This type of work requires an SME to approve it.
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-Code-QualityA section of code that is hard to understand or changeA section of code that is hard to understand or changeC-PerformanceA change motivated by improving speed, memory usage or compile timesA change motivated by improving speed, memory usage or compile timesS-Needs-Design-DocThis issue or PR is particularly complex, and needs an approved design doc before it can be mergedThis issue or PR is particularly complex, and needs an approved design doc before it can be mergedX-Needs-SMEThis type of work requires an SME to approve it.This type of work requires an SME to approve it.
Type
Fields
Give feedbackNo fields configured for issues without a type.
What problem does this solve or what need does it fill?
Currently change detection is hard-coded from userspace all the way to ECS storage. This adds quite a bit of extra effort to maintain it at every level in bevy_ecs. Logically speaking, the change ticks included are always kept parallel to the base storage, and can be seen as a companion component that is always present with every component in the World. If this is the case, it may make sense to actually make the change detection ticks their own component.
This can allow for disabling change detection entirely for types which can remove the memory and CPU overhead for small component types that don't really need it (i.e. usize newtypes or ZSTs).
This would also remove all storage-level special casing required for change detection. For example, moving entities from table to table doesn't require knowledge of the change ticks. It's copied from column to column like any other component.
What solution would you like?
ComponentTicksin storage and addChangeTicks<T: Component>as an engine provided component.Mutto fetch both&mut Tand&mut ChangeTicks<T>.Componentthat changesWriteFetchto retrieve&mut Twhen change detection is disabled, andMut<T>when it isn't. Update the derive macro to enable/disable this behavior.Component<Write=Mut<Self>>What alternative(s) have you considered?
Option<Vec<UnsafeCell<ComponentTicks>>>instead.