Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Allow toggling of components. #24

@mjstahlberg

Description

@mjstahlberg

Allow components to be enabled and disabled. Entity::Get<>() should return a nullptr and ForAll<>() should skip an entity if a required component is disabled. Messages shouldn't be handled by disabled components. A component should provide handler methods (HandleEnable and HandleDisable) so that it can react to a state change.

Here's a usage example from Unvanquished:

When I come to the point where there'll be components such as JetpackComponent, it doesn't make sense to have specialized entities for each combination of components anymore (JetpackLightarmorPulserifleGrenadeHumanClientEntity!), so I need a way to enable and disable components on existing entities during runtime. I think this functionality should be provided by the backend, otherwise you'd have a "if (!enabled) return …;" in virtually every component method and the components would falsly show up when iterating over entitites that have certain components.

One problem that could occur is that if you have a reference to a component and then that component gets disabled, you could still call its methods. I think we can/have to live with that though.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions