Skip to content

Commit f07bb3c

Browse files
authored
Add last_changed_tick and added_tick to ComponentTicks (#8803)
# Objective EntityRef::get_change_ticks mentions that ComponentTicks is useful to create change detection for your own runtime. However, ComponentTicks doesn't even expose enough data to create something that implements DetectChanges. Specifically, we need to be able to extract the last change tick. ## Solution We add a method to get the last change tick. We also add a method to get the added tick. ## Changelog - Add `last_changed_tick` and `added_tick` to `ComponentTicks`
1 parent f135535 commit f07bb3c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

crates/bevy_ecs/src/component.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,18 +744,30 @@ pub struct ComponentTicks {
744744
}
745745

746746
impl ComponentTicks {
747-
#[inline]
748747
/// Returns `true` if the component was added after the system last ran.
748+
#[inline]
749749
pub fn is_added(&self, last_run: Tick, this_run: Tick) -> bool {
750750
self.added.is_newer_than(last_run, this_run)
751751
}
752752

753-
#[inline]
754753
/// Returns `true` if the component was added or mutably dereferenced after the system last ran.
754+
#[inline]
755755
pub fn is_changed(&self, last_run: Tick, this_run: Tick) -> bool {
756756
self.changed.is_newer_than(last_run, this_run)
757757
}
758758

759+
/// Returns the tick recording the time this component was most recently changed.
760+
#[inline]
761+
pub fn last_changed_tick(&self) -> Tick {
762+
self.changed
763+
}
764+
765+
/// Returns the tick recording the time this component was added.
766+
#[inline]
767+
pub fn added_tick(&self) -> Tick {
768+
self.added
769+
}
770+
759771
pub(crate) fn new(change_tick: Tick) -> Self {
760772
Self {
761773
added: change_tick,

0 commit comments

Comments
 (0)