question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add ability to deactivate (and reactivate) components on an entity

See original GitHub issue

Currently 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:open
  • Created 6 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
immortiuscommented, May 23, 2017

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).

0reactions
Cervatorcommented, May 23, 2017

Adding in some feedback from @immortius via Slack:

It is something I’ve mused about a bit. I wouldn’t describe it as a fundamental feature of Entity Systems. It does provide a lot of convenience around removing/enabling features while retaining settings though. Wouldn’t be too hard to add to gestalt-es next time I pry myself free of other projects. It might be simplest to add an “enabled” attribute to every component. Which I can do since a lot of component details are code gen in gestalt-es. Event system would ignore them. Other things would have to check which isn’t ideal. Better is to have an active and inactive component collection for each entity. And move components between them as needed. Obviously need some methods to access the inactive store. And it needs to tie in to lifecycle events and persistence. But pretty doable. To compare to a mainstream ES (well… component system) - Unity doesn’t all individual components to be disabled, only whole entities. But then unlike Terasology the support for multi-entity constructs is pretty good in Unity.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a way to disable entities? - Unity Forum
Add the 'Disabled' component to the entities. This will result in the entity not getting returned by any EntityQueries except when explicitly ...
Read more >
Use enableable components | Entities | 1.0.0-pre.15
You can use ComponentLookup<T>.SetComponentEnabled(Entity,bool) to safely enable or disable entities from worker threads, because no structural change is needed ...
Read more >
Save date of deactivation in custom CDS entity
I assume the deactivate action happens by the user so a record can be reactivated after it's deactivated, so you might want to...
Read more >
Managing Access to Activate/Deactivate Ribbon Buttons in ...
Add the custom display rule to the Deactivate button: ... 12. In the “Command” area, Edit the display rule for the “Mscrm.HomepageGrid.Deactivate” ...
Read more >
Activating/Deactivating a component or a subJob - 8.0
You can activate or deactivate a subJob directly connected to the selected component. You can also activate or deactivate a single component as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found