UnrealEngine-ObjectPool
Unreal engine plugin providing an object pool packaged in a world subsystem for easy use.
UnrealEngine-ObjectPool: pooling actors in Unreal 5
A plugin for Unreal Engine 5, likely working in Unreal 4 as well, that provides an object pool in a world subsystem, with pooled actors implementing a provided interface.
What the plugin does
The plugin provides an object pool for Unreal Engine 5, and the README notes it probably works in Unreal 4 as well. It quotes Wikipedia's definition of the object pool pattern: a creational design pattern that uses a set of initialized objects kept ready to use rather than allocating and destroying them on demand. The project is written in C++ and released under MIT.
Why pool actors at all
The motivation is performance. Spawning a lot of actors at a high rate often causes lag spikes because so many new objects get constructed, which can be a huge problem for certain projects, a bullet hell game being the example given. The author says the plugin was created a couple of years ago and recently rewritten to be a better version.
The performance example
A performance example comes with a warning that it is an extreme case with many actors spawning each frame. The test project spawns 100 bullet actors each frame and destroys them after 0.2 seconds. Normal spawning shows a consistent performance hit and bigger garbage collection hitches later. Pooling with pre-spawn takes a big initial hit while many actors spawn at once, then settles. Pooling without pre-spawn shows frame time moving down as the pool fills.
Using the pool
There are different ways to use the pool. The pool can spawn actors automatically when empty, or a fixed amount can be pre-spawned and kept ready, or both can be combined. The README recommends pre-spawning an estimate of how many actors will be needed and allowing expansion. For each world, the engine creates an object pool manager as a UWorldSubsystem with its lifetime handled automatically. Any actor to be pooled must implement the provided Object Pooled Actor interface. A warning says that pre-spawning above about 200 actors with auto activating components like sound or VFX can freeze the game during activation.
Community notes