Object pooling VS Objects in scene.
Hello :)
I'm trying to make my game as smooth as possible. I have just implemented an object pooler in order to spawn all my enemies in the scene. This works correctly but some spikes keep in the Awake function.
So, my question is: If INSTANTIATE is a very expensive operation (also if enemies are 'pooled' in Awake() function), why not to put directly my enemies in the scene?? It could be so expensive in terms of RAM consumption??
Thanks in advance! Valerio
Answer by Dsiak · Nov 25, 2021 at 12:25 AM
I believe the point of pooling is to recycle, instead of instantiating and destroying you enable and disable the same objects. If you have a situation where all your 10 enemies are active from the get go and never respawn there is no point in pooling them, but if they comeback every 10 seconds or something its better to reuse the same game object.
Thanks @Dsiak That's Ok but in terms of RAM consumption?
There is a RAM cost to keep a pool of inactive objects, the reason they are fast is exactly because they are loaded on RAM already. I believe there should be no difference in RAM use between having 10 enemies pooled versus 10 enemies natively on the scene.
Thanks, @Dsiak , yes, this make sense. I also doubt that if I destroy an enemy, a portion of RAM frees... maybe the only way to free memory is to use addressables.