What is a good container to use for a Bullet Manager?

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.

Hi again! The method you have devised seems pretty sound to me - I’m not sure why you’d be seeing such a slow down using this strategy. What exactly are you doing every frame with respect to the bullet manager? I would only expect it to be doing anything if bullets are being activated or deactivated.

Whenever a pawn shoots, I’m also having the bullet manager handle the shooting, so maybe that’s it. If an enemy wants to fire a Spread shot, it calls the Spread function in the bullet manager, passing in the number of bullets it wants to shoot and its own location. Bullet movement is still handled in the bullet’s tick though. The bullet manager doesn’t tick.

Hmmm, nothing there sounds out of the ordinary :confused:
It’s probably just worth checking that the arrays aren’t being resized in someway (ie, don’t allow shrinking unless there’s ie > 50% slack) or something like that. Provided you’re not looping over the arrays needlessly there’s probably something else at fault.

Yeah, I guess it’s time to learn about the Profiler. Needed to happen sooner or later haha. Thanks for the help, Andrew.