Skip to content

Add a getter for SystemMeta::last_run (or help me not need it?) #22487

@stinkytoe

Description

@stinkytoe

What problem does this solve or what need does it fill?

I am implementing a custom SystemParam for my plugin Shieldtank. This is meant to be a framework for loading LDtk files.

LDtk objects provide a UUID for each object in in their document tree, which they call an Iid. Right now I'm adopting their nomenclature. I have added a component which is auto inserted whenever an entity is created from one of these assets, which basically wraps this Uuid. See iid.

I though it would be nice to provide the user with a SystemParam similar in behavior to Single which I currently call SingleByIid (might change name later). This object takes the u128 representation of the Uuid as a generic parameter, so that the user can insert it into the signature of their system.

Here's two game demos I'm developing in conjunction with this plugin as proof of concept, both of which use this SystemParam: axe_man_adventure dungeon_of_madness.

The problem I'm having is in the manual trait impl for my SingleByIid struct. I basically shamelessly copied bits and bobs from Bevy's Single and Populated. The problem is though, both Single and Populated, when they implement SystemParam, use a line similar to the following:

 let query = unsafe {
     state.query_unchecked_with_ticks(world, system_meta.last_run, world.change_tick())
 };

The field SystemMeta::last_run is pub(crate), and therefore not usable to me.

I tried using UnsafeWorldCell::last_change_tick in its place, but it would fail to yield when the QueryFilter would include a change detection filter, such as Changed<GlobalTransform>. (Though it worked with Changed<Transform>?). It would also fail Changed<ShieldtankGlobalBounds>, which is one of my components.

Anyways, I forked Bevy and added a SystemMeta::get_last_run getter for that field. Using this getter method, change detection now works as I expect, at least in all of the testing and experimentation I've done. my fork

I would be glad to file a PR from my fork, if y'all would consider excepting it. But, I wanted to write this Issue first to make sure this is the right way to fix this.

Is there another way for me to overload the validate_param trait method? Or, another way to generate the query with provided methods that would work?

Am I smoking crack here for trying this?

What solution would you like?

Add SytemMeta::get_last_run, or give me the green light to submit my fork as a PR.

What alternative(s) have you considered?

Using UnsafeWorldCell::last_change_tick works most of the time, but not when the QuerFilter has change detection type queries. But only some times.

Additional context

Y'all are awesome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions