From 7526606febd8595bb23fdec033b660241724b5ca Mon Sep 17 00:00:00 2001 From: Rafael Almeida Date: Mon, 4 Feb 2019 09:08:39 -0200 Subject: [PATCH] Notify subscribers before removing components from entity (#589) --- Source/MonoGame.Extended.Entities/EntityManager.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/MonoGame.Extended.Entities/EntityManager.cs b/Source/MonoGame.Extended.Entities/EntityManager.cs index 4113e37b..529130a6 100644 --- a/Source/MonoGame.Extended.Entities/EntityManager.cs +++ b/Source/MonoGame.Extended.Entities/EntityManager.cs @@ -98,15 +98,15 @@ namespace MonoGame.Extended.Entities foreach (var entityId in _removedEntities) { + // we must notify subscribers before removing it from the pool + // otherwise an entity system could still be using the entity when the same id is obtained. + EntityRemoved?.Invoke(entityId); + var entity = _entityBag[entityId]; _entityBag[entityId] = null; _componentManager.Destroy(entityId); _entityToComponentBits[entityId] = default(BitVector32); ActiveCount--; - - // we must notify subscribers before removing it from the pool - // otherwise an entity system could still be using the entity when the same id is obtained. - EntityRemoved?.Invoke(entityId); _entityPool.Free(entity); }