You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Create manual set_changed and set_added methods #1718
What problem does this solve or what need does it fill?
Existing solutions to manually toggle entities as changed or added are unclear and clunky workarounds.
You might want to do this if, for example, you need to re-process an entity as changed even though its data was not set directly.
What solution would you like?
Create either commands.entity(e).set_changed() or commands.entity(e).set_changed(bool). Uses new syntax from #1703.
Also create set_added and World variants of the above.
What alternative(s) have you considered?
For set_changed, you can manually deref_mut a component, but this is a bit more obscure and requires mutable access to the component.
For set_added, you can manually remove and re-add a component, but this is expensive, slow (WRT command processing) and obscure.
Additional context
Discussed in #1471 and #1711. The bool form of the new methods is more powerful, but also slightly more verbose, and might not have great use cases / present a footgun. I'm personally in favor of the bool method in order to provide more expressive power, but it would be good to have a more full discussion.
I'm personally in favor of the bool method in order to provide more expressive power, but it would be good to have a more full discussion.
What value would you store in ComponentTicks for false? If you want a more powerful method, I would recommend taking the desired change_tick value as a parameter instead. IMO we should wait for a good use case to show up before considering either of these.
Create either commands.entity(e).set_changed() or commands.entity(e).set_changed(bool). Uses new syntax from #1703.
Also create set_added and World variants of the above.
Using commands has the drawback of being delayed. For an instantaneous solution, we can add these two methods on ChangeTrackers. Moreover, ChangeTrackers is available both in parallel systems and on direct world access, through queries.
If we roll with the ChangeTrackers impl, we'll need to create a new ChangeTrackersMut. We aren't allowed to mutate component ticks without unique access, and ChangeTrackers only requires immutable access
Activity
Davier commentedon Mar 22, 2021
What value would you store in
ComponentTicksforfalse? If you want a more powerful method, I would recommend taking the desiredchange_tickvalue as a parameter instead. IMO we should wait for a good use case to show up before considering either of these.Using commands has the drawback of being delayed. For an instantaneous solution, we can add these two methods on
ChangeTrackers. Moreover,ChangeTrackersis available both in parallel systems and on direct world access, through queries.cart commentedon Mar 22, 2021
If we roll with the
ChangeTrackersimpl, we'll need to create a newChangeTrackersMut. We aren't allowed to mutate component ticks without unique access, andChangeTrackersonly requires immutable accessalice-i-cecile commentedon Dec 12, 2021
Fixed by #2208.