#Deleting Entities

1 messages · Page 1 of 1 (latest)

fresh sand
#

I have a a list of entities and i want to delete some of them.

var entities = _jobQuery.ToEntityArray(Allocator.TempJob);

I'm looping though them and calling .DestroyEntity(entities[i]) from a EntityCommandBuffer - but do i need to also dispose of the IDataComponents on my entities so they don't leak memory or will DOTS take care of that for me?

runic surge
#

If you delete entities their components will be deleted as well. The only exception are SystemStateComponents (I think CleanupComponent in 1.0) which have the exact purpose of staying around after entity deletion

#

If the entities you want to delete match a specific query you can pass a query directly to the EntityManager or an EntityCommandBuffer to delete. You dont need to schedule a job and iterate through them

fresh sand
#

Thanks Peaj - it's only in rare cases if they user changes the count of a specific query - there might be 1000 entities and if they count is changed to 500 - i will loop through the first 500 and call Destroy on those

#

Not sure if i can make a query that will match the first 500 of an otherwise query using a .SetSharedComponentFilter

misty pagoda
#

If for some reason you have a persistent native container on those IDataComponents then you would still need to dispose that

misty pagoda
#

which i imagine would be better performance

#

theres also DestroyEntity(EntityQuery) to destroy a whole query