Array of enemies, first one in, last one out.

So yay! I finally built to my phone and I’m noticing a slight pause in the gameplay when their is a new wave of enemies spawned.

I know that it is from my instantiating them. So I need to change that into an array of enemy game object held off screen, and the spawner needs to pull from that array. However. How does that work?

I remember someone telling me about this “first one in, last one out” system. But I’ve done a search and so far I can’t find even a mention of this system, let alone an example of how it works.

Can someone point me in the right direction?

You are looking for Pooling. The concept of pooling objects is to create them at the start and then keep them deactivated until needed. When finished with the object it is placed back in the pool. Here is good thread on it:!

what you are looking for is objects pool. in object pool you pre create the objects and then just enable them when you need them. when you done you disable them and they return to the pool.

here good article about this: C# Memory Management for Unity Developers (part 3 of 3)

if you don’t want to write your own there good few assets that will do the job.

since we posted almost the same answer at the same time i would like to add recommendation to product i’m working with that may help you: