Most performant way of entity instantiation and destruction (DOTS/ECS)

There seems to me to be two ways of adding components to entities:

  • One is shown in this tutorial, where components are added by using an [GenerateAuthoringComponent] attribute on a IComponentData added to a monobehaviour.

  • Not shown is another, where components are added using an entitymanager after the prefab has been converted to an entity and instantiated.

I am working on a project where I will spawn and destroy a large number of entities (apprx 1 to 5 per second, each having a large pathbuffer pushing the size restrictions for each entity), and I try to eke out all the performance benefits I can from DOTS. Is your system of instantiation more performant?

Also (a bit above and beyond this lesson in particular) is there a benefit to pooling entities rather than destroying them like there is for prefabs?

Cheers,

It’s interesting and cool to see ECS/DOTS come up.

From my understanding, if you do it fully ECS/DOTS, you won’t need to pool. If you do (If I remember right, it’s called the hybrid approach?) where you have a conbination of the old way and ECS, then you’ll see a benefit from pooling.

There’s a couple of reasons pooling is performant. Constructing objects (chunks of memory on the heap) takes up a fair chunk of resources. The garbage collector also takes up resources.

My understanding is the whole idea of DOTS/ECS is to utilize the stack memory (super fast compared to the heap memory, but computers only have limited amount of stack memory) as much as possible.

At a quick look at how Nathans course was described, I’d guess it’s not doing much hybrid stuff, so you’ll probably find pooling ain’t going to help you much.

That all being said, I’m not too experienced in Dots/ecs/jobs. I did a course on it quite a while back but I don’t believe I was at the expereince level in Unity/C# for much of it to sink in, so I should go back and go through it again… but I’d love to see more posts in the forum about it.

1 Like

Privacy & Terms