TinyEcs icon indicating copy to clipboard operation
TinyEcs copied to clipboard

Component Lifecycle Terms

Open xentripetal opened this issue 9 months ago • 9 comments

Hey I really like the direction you're taking this library! I've been bouncing between different ECS libs and this seems like a great option.

It would be very helpful if queries had support for defining filters based on the lifecycle of components.

Mainly:

  1. Changed<T> - Evaluates to true when component T was accessed mutably or set for the entity since the last execution of the query

  2. Added<T> - Evaluates to true when component T was added to an entity since the last execution of the query

I'm not fully sure how bevy does this but it seems like they store a vec of watermarks alongside each column that gets updated each time an entry in the column is accessed mutably or added. Then each query tracks a watermark of when it was last ran it uses for comparison. https://github.com/bevyengine/bevy/blob/main/crates/bevy_ecs/src/change_detection.rs https://bevy-cheatbook.github.io/programming/change-detection.html

  1. Removed<T> - Evaluates to true when component T was removed from an entity since the last execution of the query

In bevy, removals publish out an event that systems can read if they run the next frame https://github.com/bevyengine/bevy/blob/main/crates/bevy_ecs/src/removal_detection.rs

xentripetal avatar Apr 29 '24 04:04 xentripetal