I’m working on a shmup (shoot 'em up). I need a Bullet Manager since creating and destroying many bullets every tick is too costly. I need to just create them once and have a fast way to recycle them.
The way I’m doing this now is with 2 arrays. My bullet object has a bool that determines whether it is active or not, plus an integer index. The first array, called InactiveBullets, holds the indexes to all bullets. The other, called BulletPool, holds pointers to the objects themselves. Whenever I need a bullet, I pop an index off of InactiveBullets and use that index to determine which bullet in the BulletPool should become active. When a bullet hits something, it deactivates and pushes its index back onto InactiveBullets. When a bullet becomes inactive, I hide it and disable its tick.
While it’s much faster than creating new bullet objects every tick, I feel like there is a better way. I can only have about 100 bullet particles on screen before things start to lag. That’s a long way from the several thousand that I’m looking for. The particles themselves are not at all complex. Basically just a texture. Is there another container in UE4 that might be more appropriate for this sort of thing? I’ve only worked with regular old arrays and although I’ve read about other containers, I don’t know what would be best for this situation.