Skip to content

Make ComponentTicks available from ChangeTrackers#7410

Closed
chrisjuchem wants to merge 1 commit intobevyengine:mainfrom
chrisjuchem:bevy_mod_index
Closed

Make ComponentTicks available from ChangeTrackers#7410
chrisjuchem wants to merge 1 commit intobevyengine:mainfrom
chrisjuchem:bevy_mod_index

Conversation

@chrisjuchem
Copy link
Contributor

Objective

To implement indexes, I need to be able to check if a component has changed since an arbitrary time, not just since the last time the system ran.

Solution

Allow for getting a read only reference to ComponentTicks from ChangeTrackers so that ComponentTicks::is_added and ComponentTicks::is_changed can be used, since they take the last_change_tick as a parameter.

Alternatives

Implement is_added_since and is_changed_since on ChangeTrackers itself, deferring to ComponentTicks under the hood.

Changelog

  • Added ticks method to ChangeTrackers to get the ComponentTicks tracking when a component was added/changed.

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Jan 29, 2023
@alice-i-cecile
Copy link
Member

It feels like the DetectChanges trait is the right place for this functionality, rather than special-casing this for ChangeTrackers.

@chrisjuchem
Copy link
Contributor Author

Makes sense, I'll move it there.

@joseph-gio
Copy link
Member

joseph-gio commented Jan 30, 2023

FYI, ChangeTrackers will probably get removed (see #7306). So this code from bevy_mod_index:

type ChangedComponetsQuery<'w, 's, T> = Query<
    'w,
    's,
    (
        Entity,
        // TODO: Figure out if the static lifetime is right here
        &'static <T as IndexInfo>::Component,
        ChangeTrackers<<T as IndexInfo>::Component>,
    ),
>;

Would become this:

type ChangedComponetsQuery<'w, 's, T> = Query<
    'w,
    's,
    (
        Entity,
        Ref<'static, <T as IndexInfo>::Component>,
    ),
>;

Also: the static lifetime is indeed correct here. The lifetimes bound to WorldQuery types don't really matter -- WorldQuery::Item<'w> is where the lifetimes start to matter.

@chrisjuchem
Copy link
Contributor Author

Thank you for the pointers @JoJoJet.

It turns out that DetectChanges actually already provides last_changed which was enough for me to implement what I needed, so this PR is no longer needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants