#Pooling in ECS?

1 messages · Page 1 of 1 (latest)

peak ivy
#

Hey fellas! Hope you're all doing good. Ive been toying with ECS for a bit and i looked for an answer for my question but ive seen a lot of division when it comes to this subject:

Should i pool Entities? Pooling is a pretty standard pattern in common monobehaviour development, but what about ECS? Is it something that is sensless here?

I cant really imagine how i would even use a pool for this, but my mind goes back to "constant instantiation and destruction are bad". Im making a bullet hell game and constantly spawning bullets and destroying them feels wrong, but im not sure if it is wrong. Thank you very much for any insight!

dim oak
#

pooling entities aren't required and would likely be a performance loss in most cases

#

however if you use any gameobejct companions as a hybrid approach, pooling those objects can make sense

peak ivy
#

i see, i can imagine how pooling entities could cause more issues than solve them

#

do you have any links or documentation or project sample i could use to take a deeper look into this hybrid approach you mention? So far i am using prefab entities so i cant really imagine a case where i would use a hybrid approach, but could perhaps be intresting

torpid palm
#

in some cases you might want to add a traditional GameObject component that doesn't (yet) have an ecs version, such as ParticleSystem, to an entity

#

there's a limited list of such components but what happens with them is that they get created as normal managed components with a hidden backing GameObject per Entity

#

similarly you can define components as classes instead of structs for cases where you need to interface with a managed-code api or third party library, and as classes they are subject to gc so allocating and deallocating them results in gc pressure

barren axle
#

In this demonstration, there are 2 versions for the hybrid approach:

  • Version 1: I manage the gameobjects on my own, using a custom object pooling optimized for ECS.
  • Version 2: I use the gameobject companion from Unity ECS Hybrid module.
#

I would suggest version 1 if you're going to spawn and destroy a vast amount of entities of the same kind in a short frame time. Because you can reuse the already allocated gameobjects and avoid GC cleanup.

#

On the other hand, for a reasonable number of entities of many kinds, or they will be rarely destroyed, you should use version 2 (companion gameobjects) for the simplicity of the setup.

#

But of course, as anttirt said, only a small number of GO components are applicable for companion gameobjects.

peak ivy
#

All of this is incredibly helpful. Thank you very much everyone! I will be taking a look at all of this