Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create manual set_changed and set_added methods #1718

Closed
alice-i-cecile opened this issue Mar 21, 2021 · 3 comments
Closed

Create manual set_changed and set_added methods #1718

alice-i-cecile opened this issue Mar 21, 2021 · 3 comments
Labels
A-ECS Entities, components, systems, and events C-Enhancement A new feature C-Usability A simple quality-of-life change that makes Bevy easier to use

Comments

@alice-i-cecile
Copy link
Member

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.

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Enhancement A new feature C-Usability A simple quality-of-life change that makes Bevy easier to use labels Mar 21, 2021
@Davier
Copy link
Contributor

Davier commented Mar 22, 2021

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.

@cart
Copy link
Member

cart commented Mar 22, 2021

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

@alice-i-cecile
Copy link
Member Author

Fixed by #2208.

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-Enhancement A new feature C-Usability A simple quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

No branches or pull requests

3 participants