Spy-Shifty / BrokenBricksECS

Rebuild of Unity3D upcoming Entity Component System !OUT OF DEVELOPMENT!
MIT License
162 stars 28 forks source link

Enabling/Disabling/Enabling still removes components #28

Open enzi opened 6 years ago

enzi commented 6 years ago

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 commented 6 years ago

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); }