diff --git a/ashley/src/com/badlogic/ashley/core/Engine.java b/ashley/src/com/badlogic/ashley/core/Engine.java index 02191d91..a2e9ae75 100644 --- a/ashley/src/com/badlogic/ashley/core/Engine.java +++ b/ashley/src/com/badlogic/ashley/core/Engine.java @@ -125,6 +125,10 @@ public void addEntity(Entity entity){ */ public void removeEntity(Entity entity){ if (updating || notifying) { + if(entity.scheduledForRemoval) { + return; + } + entity.scheduledForRemoval = true; EntityOperation operation = entityOperationPool.obtain(); operation.entity = entity; operation.type = EntityOperation.Type.Remove; @@ -273,6 +277,7 @@ else if (belongsToFamily && !matches) { } protected void removeEntityInternal(Entity entity) { + entity.scheduledForRemoval = false; entities.removeValue(entity, true); if(!entity.getFamilyBits().isEmpty()){ diff --git a/ashley/src/com/badlogic/ashley/core/Entity.java b/ashley/src/com/badlogic/ashley/core/Entity.java index 4b5a4133..f680a689 100644 --- a/ashley/src/com/badlogic/ashley/core/Entity.java +++ b/ashley/src/com/badlogic/ashley/core/Entity.java @@ -51,6 +51,7 @@ public class Entity { private Bits componentBits; /** A Bits describing all the systems this entity was matched with. */ private Bits familyBits; + boolean scheduledForRemoval; ComponentOperationHandler componentOperationHandler; @@ -239,4 +240,11 @@ public boolean equals(Object obj) { static long obtainId() { return nextId++; } + + /** + * @return true if the entity is scheduled to be removed + */ + public boolean isScheduledForRemoval() { + return scheduledForRemoval; + } } diff --git a/ashley/src/com/badlogic/ashley/core/PooledEngine.java b/ashley/src/com/badlogic/ashley/core/PooledEngine.java index 7370b596..cdfed973 100644 --- a/ashley/src/com/badlogic/ashley/core/PooledEngine.java +++ b/ashley/src/com/badlogic/ashley/core/PooledEngine.java @@ -119,6 +119,7 @@ public void reset() { flags = 0; componentAdded.removeAllListeners(); componentRemoved.removeAllListeners(); + scheduledForRemoval = false; } }