Skip to content
This repository was archived by the owner on Aug 30, 2018. It is now read-only.

Enabling/Disabling/Enabling still removes components #28

Open
enzi opened this issue Feb 11, 2018 · 1 comment
Open

Enabling/Disabling/Enabling still removes components #28

enzi opened this issue Feb 11, 2018 · 1 comment

Comments

@enzi
Copy link

enzi commented Feb 11, 2018

Components get removed when you call the following code in a single frame on a GameObjectEntity:

gameObject.SetActive(true); gameObject.SetActive(false); gameObject.SetActive(true);

The gameobject stays active but its components and monobehaviours get removed.

@enzi
Copy link
Author

enzi commented Feb 12, 2018

Alright I wrote a fix for this.

Add this to EntityManager.cs
public virtual void SuppressDeletion<TComponent>(Entity entity, TComponent component) where TComponent : IComponent { _deletableComponents.RemoveWhere(m => m.entity == entity && m.componentArray.ComponentType == typeof(TComponent)); }
and in ComponentWrapper.cs:

if (gameObjectEntity.EntityManager.HasComponent<TComponent>(gameObjectEntity.Entity)) { _component = gameObjectEntity.GetComponentFromEntityManager<TComponent>(); gameObjectEntity.EntityManager.SuppressDeletion(gameObjectEntity.Entity, _component); // add me } else { gameObjectEntity.EntityManager.AddComponent(gameObjectEntity.Entity, _component); }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant