Closed zewa666 closed 2 days ago
I see that on current master there is a function called getRemovedEntities
so that might serve as another option to check in a system and perform cleanups. Does this library follow any specific npm release cycles since it seems the last release is quite behind the current master state
i think exit queries can help you here @zewa666
const Sprite = defineComponent()
const spriteQuery = defineQuery([Sprite])
const exitedSpriteQuery = exitQuery(spriteQuery)
exitedSpriteQuery.forEach(eid => {
// cleanup sprites here
})
not sure if that solves your issue or not.
i've heard some users of bitECS implement their own Remove
tag & query so they can have more control over removals/recycling of IDs.
another strategy is to create your own customRemoveEntity
function which calls removes all components from an entity and then adds the entity to a queue. the queue can be drained at the end of a frame, calling bitECS's removeEntity
on each ID in the queue to safely hand back the EID to bitECS for recycling.
i do create releases when i deem master
branch to be stable. it's nearing stability, should have a release out in the next couple weeks.
thanks for the response, I went with the wrapped removeEntity approach + a postcleanup on end game to clear all potential leftovers
observers and manual entity recycling can be used to address this now:
Hey there,
I'd like to know what approach to take to perform some cleanup after an entity has been removed. So e.g I have a map of <eid, sprites> where once the entity is removed, the according entry of the map should be deleted.
I thought about perhaps about instead of calling removeEntity directly instead do
addComponent(world, AboutToBeDead, eid)
and in the enterQuery of listening for AboutToBeDead, to perform the cleanup and call removeEntity afterwards. It feels like a workaround though.