OBJECT POOL PLUGIN(Object Pool Plugin in Code Plugins - UE Marketplace)
HOW TO USE:
Be sure that you have the plugin installed and ready to use for your Unreal Engine:
To use the pooling system you have to create (or reparent existing) Actor classes to be compatible with **Pool Component **containers.
There are three base classes for this purpose, you can create a Pooled Actor class, a Pooled Pawn class, or a Pooled Character class:
The reason for re-parenting to, or creating new of, these special classes is for C++ system perform complex memory management outside the “World of Blueprints”. With your classes being children of these core classes the plugin can manage them without really having to know which class your Actor exactly is.
It’s the Pool Component that does this managed in C++ for you, automatically. It tricks Unreal to reset and recycle an existing allocated Actor instead of creating new memory for yet another Actor to do what our existing Actor already does. The results are massive performance improvements under circumstances where your game must frequently spawn Actors of similar or equal classes all the time. Because “Begin Play” and “End Play” can only execute on newly created Actors or Actors that are being destroyed, your Pooled Actor classes also contains special events called “On Pool Begin Play” and “On Pool End Play”. These special events will execute in your Blueprints whenever an instance is activated by the Pool Component’s container and whenever it is deactivated:
From those events you can execute pretty much anything that you would need to execute on “Begin Play”, very convenient.
There’s four different types of Pool Components provided by the plugin. One deals with generic Pooled Actor classes, another one for Pooled Pawn classes, another one is for managing Pooled Characters, and the last one is a Shared Pool for managing several classes of Pooled Actors all spawned by the same Pool Component.
There’s a VERY IMPORTANT rule you have to keep in mind when dealing with Pool Components!
This rule is: Do NOT add Pool Components to be a member of Pooled Actors that are spawned by that same Pool Component class.
Infinite loop happens if you do that. Don’t do it.
Pool Component’s Properties:
Pool Components expose to you three basic properties for generating a Pool of Actors for you.
Template Class: Select the base class of Actors you want Pool Component to create and manage.
Pool Size: How many pre-allocated Pooled Actors you need? you can set how many you want here.
Auto Initialize: On Begin Play the Pool Component will spawn and keep in memory instances of the Template Class.
Very simple, all the rest is done by the Pool Component in C++ world.
Pool Component’s Spawn Functions:
Once you have your Pooled Actor classes, Pool Components in place, and have set the Template Class correctly, the Blueprint housing the Pool Component can get an easy reference to it and call either “Spawn Actor from Pool”, “Spawn Pawn from Pool”, or “Spawn Character from Pool” nodes. Depending on which kind of Pool Component you have set:
IMPORTANT: Since v1.9.0, you have to pick a target class on both the Pool Component (Template Class) and on the Spawn from Pool nodes.
This is the way it is to fix a problem regarding “Exposed on Spawn” properties not adding pins to the Spawn from Pool nodes.
When it comes to projectile movement, you cannot pool the default movement component of Unreal Engine.
That component is made to move Actors that have just being created and once it stops you cannot recycle the functions. Making you feel forced to spawn a new Actor every time your weapon shoot a new bullet. So, instead of using default projectile movement component on your Pooled Actors, bullet actors, you have to use a custom movement component provided by the plugin: a Pooled Projectile Component:
Alternatively, for fancy effects, the v1.9.0 plugin also provides a Spline Projectile Component that can be used to travel bullets along a spline path:
With this component you can simulate a bullet without the Pooled Actor using any actual physics simulations, the projectile can have collisions and simulation disabled. The collision detection is done by the Spline Projectile Component in C++ using sphere traces:
To use a Spline Projectile Component you must pass into each instance of your Pooled Actors in your Pool Component to use a Spline Component that you have created. The Spline Component’s points will provide to the projectile the path and orientation to follow when the bullet is shot. Here’s is how you can pass into instances of projectiles an Spline Component to use:
And then you can use Spawn Actor from Pool nodes as usual, once activated a bullet Actor is going to follow the Spline you provided:
Dealing with Niagara Particle Components on Pooled Actors:
You have to activate “Force Solo” option on your Niagara Component.
Niagara will disable GPU pooling and allow you to do CPU pooling of the component: