Hi there,
maybe it’s a stupid question but I can’t find an answer while searching for hours now: i want to have visible footsteps that disappear after a while.
For deleting entities I found out that I should delete the entities using injected data but my VisualStudio says that it can’t find the type or namespace for things like the ‘Inject’ attribute, the types ‘EntityArray’ or ‘ComponentDataArray’:
What am I missing here? Some package I have not downloaded?
Hm ok, that’s why I can`t get it working… what would be a correct approach to have my footprint entities disappear (be removed) when they reach their liftetime?
Mh, my packages are up-to-date… that [Inject] attribute is something I stumpled upon while searching for an answer… it is nothing I actually use, only something I tried and could not get to work…
Is destroying an entity from inside a ComponentSystem really that complicated? I just want to destroy an entity a soon as a certain value reaches 0.
If you are destroying more than 1 entity in a frame its best for performance to do that via a command buffer so all destroys get executed together at the same time.
You can use PostUpdateCommand or provide an alternative buffer for the job to use, for example:
World.GetOrCreateSystem();
That’s not actually true in a ComponentSystem. To get fast deletion in a ComponentSystem, you would want to use a NativeList and add all the entities to delete and then afterwards, EntityManager.DestroyEntity(list.AsArray).
But I’m pretty sure that EntityManager.DestroyEntity(entity) one by one is still faster than using PostUpdateCommands.
Last I heard every time you add or remove an entity a bunch of queries and chunks get invalidated and need to be changed or re-built. By using a command buffer you reduce that to one time instead of multiple times.
Fasten way is use native array in Destroy as @DreamingImLatios mentioned, but fastest as possible is EntityManager.Destroy with EntityQuery overload. CommandBuffer one by one doing same thing like EM destroy one by one and no matter when you’ll be doing that, it will cause many structural changes and chunk rearrangements which in turn will cause performance hit. But all depends on entity for destroy count For few lightweight entities it haven’t much difference.