Open enzi opened 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); }
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.