Add ability to deactivate (and reactivate) components on an entity
See original GitHub issueCurrently we don’t have the ability to deactivate or suppress a component from an entity temporarily. As this is a key advantage of an ECS I think it’s something that should be added.
I feel that the best way to do this is to add two new methods to an entity. deactivateComponent
and activateComponent
. These would work in the same way as getComponent
, taking a Class which if it exists on the entity would be activated or deactivated.
hasComponent
would return false if the component is deactivated to ensure that behaviour is as expected, likewise getComponent
will return null.
Implementing this would involve adding new methods to ComponentContainer
(and those that implement it) to activate and deactivate components. A new store would be added to PoioEntityManager
to keep track of the deactivated components and to allow for getComponent
and related methods to be updated. This would in turn ensure that events are handled correctly as well.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (9 by maintainers)
Top GitHub Comments
I really don’t think disabling health would be a good approach to invulnerability for multiple reasons (e.g. if you have a health bar above an enemy, it would disappear when the enemy is invulnerable, which is not great).
Adding in some feedback from @immortius via Slack:
So the base support for this might best go in the new v6 of Gestalt that includes the entity system in our external library, which still needs to be adopted for the Terasology engine. Unsure if that might push this to a v2.0.0 release due to backwards incompatible reasons. Should also include some doc updates and ideally another tutorial or two - comes with new features.
One use case I’m curious about: What if a player drinks an invulnerability potion, inactivating the health component, and then drinks a max health boost potion? Would that seek out a
HealthComponent
even if inactive to apply the effect for whenever invulnerability wears off? Or should gameplay logic dictate such a potion would have no effect if timed like that? Sounds like that might be too inflexible, so maybe checking for inactive would be right.