Skip to content

Disable and enable entities #11090

Closed
Closed
@alice-i-cecile

Description

@alice-i-cecile

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

For gameplay or performance reasons, it is common to want to temporarily disable entities.

While disabled, they should generally not be interacted with in any way.

What solution would you like?

Add a special Disabled marker component. Entities with this component do not appear in any queries, unless the query contains With<Disabled> (or otherwise explicitly requests that component).

I'm indifferent to either hard-coding a single type for this, or making this behavior an associated constant on the Component type. The former is simpler, but the latter is end-user extensible and arguably more elegant.

What alternative(s) have you considered?

Respawning

We could save, despawn and then respawn the entities. However it is both simpler and faster to keep the entities alive but filter them from (most) queries.

Additionally, reading the data of despawned and stored entities is much more challenging.

Custom marker component

Users could add a Disabled marker component of their own, and then add Without<Disabled> to all of their systems.

However:

  1. This is a lot of boilerplate.
  2. There is no standard across the ecosystem.
  3. External systems will continue to operate on them.

Additional context

flecs has a Disabled component and a Prefab component that work in this fashion. It also has a Prefab component which works in the same way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleD-ComplexQuite challenging from either a design or technical perspective. Ask for help!S-Needs-DesignThis issue requires design work to think about how it would best be accomplishedX-BlessedHas a large architectural impact or tradeoffs, but the design has been endorsed by decision makers

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions