There are some cases where I want to simply iterate over all existing entities in a world.
Lacking a function in the API, my first thought was using an "empty" query.
Since the typings for defineQuery require an array, I passed in an empty one []
I haven't tested this thoroughly, but calling removeEntity while iterating this query has strange behavior. The first run through, it goes fine. After adding some entities back to the world, running the query again will only iterate entities that weren't deleted in the first query call. None of the new entities show up.
When calling defineQuerywithout the [] argument, it works much better. However, the array returned by this query will be mutated as you delete entities, so you need to clone it first if you want to get every entity (or maybe a while(entities[0]) loop works). This is different than queries with components, which defer the removal.
I'd rather avoid these unexpected behaviors entirely by having a simple function to get all my entities, and have it return an array that will not be mutated by removeEntity.
There are some cases where I want to simply iterate over all existing entities in a world.
Lacking a function in the API, my first thought was using an "empty" query.
Since the typings for
defineQuery
require an array, I passed in an empty one[]
I haven't tested this thoroughly, but calling
removeEntity
while iterating this query has strange behavior. The first run through, it goes fine. After adding some entities back to the world, running the query again will only iterate entities that weren't deleted in the first query call. None of the new entities show up.When calling
defineQuery
without the[]
argument, it works much better. However, the array returned by this query will be mutated as you delete entities, so you need to clone it first if you want to get every entity (or maybe awhile(entities[0])
loop works). This is different than queries with components, which defer the removal.I'd rather avoid these unexpected behaviors entirely by having a simple function to get all my entities, and have it return an array that will not be mutated by
removeEntity
.