We cannot safely destroy an entity as World.update is being run because EntityManager::Views may still have references to the entity and try to access other components. To work around this World.destroy_entity() needs to initiate a delated destroy of the entity.
World.destroy_entity()
Add ViewExemptComponent and DeletedComponent to the entity
Create System::Janitor
Subscribes to ViewExemptComponent and DeletedComponent
calls World.entity_manager.delete_entity
This should work because the lifetime of the entity will be:
created; accessible to all
during update destroy requested: still accessable to all during this update
next update, due to ViewExemptComponent it should not show up to any other Systems, but Janitor, who can explicitly call EntityManager.destroy_entity.
Only concerns is another system making use of ViewExemptComponent, but they'll just have to exclude DeletedComponent.
We cannot safely destroy an entity as
World.update
is being run becauseEntityManager::View
s may still have references to the entity and try to access other components. To work around thisWorld.destroy_entity()
needs to initiate a delated destroy of the entity.World.destroy_entity()
ViewExemptComponent
andDeletedComponent
to the entityViewExemptComponent
andDeletedComponent
World.entity_manager.delete_entity
This should work because the lifetime of the entity will be:
ViewExemptComponent
it should not show up to any other Systems, but Janitor, who can explicitly callEntityManager.destroy_entity
.Only concerns is another system making use of
ViewExemptComponent
, but they'll just have to excludeDeletedComponent
.