Skip to content

Create manual set_changed and set_added methods #1718

Closed

Description

@alice-i-cecile

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.

Activity

  1. added
    A-ECSEntities, components, systems, and events
    C-FeatureA new feature, making something new possible
    C-UsabilityA targeted quality-of-life change that makes Bevy easier to use
    on Mar 21, 2021
  2. Davier commented on Mar 22, 2021

    @Davier
    Contributor

    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.

  3. cart commented on Mar 22, 2021

    @cart
    Member

    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

  4. alice-i-cecile commented on Dec 12, 2021

    @alice-i-cecile
    MemberAuthor

    Fixed by #2208.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions