Implement DetectChanges
for tuples and derived SystemParam
s
#13392
Labels
A-ECS
Entities, components, systems, and events
C-Usability
A simple quality-of-life change that makes Bevy easier to use
D-Modest
A "normal" level of difficulty; suitable for simple features or challenging fixes
X-Contentious
There are nontrivial implications that should be thought through
What problem does this solve or what need does it fill?
At the moment
DetectChanges
is implemented forRes<T>
,ResMut<T>
, and some other system parameters but not for tuples thereof.I've rolled some of my own generic system parameters which use
DetectChanges
and the lack of tuple support is very annoying.For example I have
Cached<R: ReadOnlySystemParam + DetectChanges, V>
which gives you a valueV
which is automatically recalculated only ifR
changes (this is useful if recalculating the value is expensive). This works whenR
is a single resource but it would be lovely if it could also work for tuples of resources and types with `#[derive(SystemParam)]I have a feeling that the reason this hasn't been done already is that
DetectChanges
has thelast_changed(&self)
method which I'm not sure is possible to calculate for tuples. It would seem trivial - just take the max of the member values - but the wayTick
works is that it wraps around at a certain number so the highest value is not necessarily the most recent.What solution would you like?
The outcome I would like is to be able to call
is_changed()
on tuples like(Res<T>, ResMut<U>)
and similar, more complex nested tuples and appropriate types with #[derive(SystemParam)]I don't think there's a way to do this without breaking changes (or an incorrect
last_changed
implementation) but I think the best way to do this would be to splitDetectChanges
into two traits: one foris_added
andis_changed
and the other forlast_changed
.What alternative(s) have you considered?
last_changed
could be changed to take the current tick of the system and that could be used as a reference to deal with the wraparound.DetectChanges2
trait that I've implemented for the types I need. This is quite annoying though as it leads to some extra boilerplate.The text was updated successfully, but these errors were encountered: