Announcement

Collapse
No announcement yet.

Plugin Object Pool Component

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • started a topic [SUBMITTED] Plugin Object Pool Component

    Plugin Object Pool Component


    This is not just a simple script to hide/show actors.

    The classes implemented by this plugin builds for you a fully working Object Pool system super easy to use.

    It's blazing fast, carefully implemented to reduce overhead as much as possible, making viable to have thousands of actors flying around with minimum performance impact while not falling to the quirks and weirdness of instanced meshes. This is specially useful for VR and Mobile platforms!


    HOW TO USE:
    * [ This is reference material for the 1.9.0 version, submitted for Unreal 4.22+]

    __________________________________________________
    Install Plugin:

    Be sure that you have the plugin installed and ready to use for your Unreal Engine:



    __________________________________________________
    Pooled Classes:

    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:



    __________________________________________________
    Pool Events:

    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.

    __________________________________________________
    Pool Components:

    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.


    PROJECTILES:

    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:


    SPLINE PROJECTILES:

    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:

    Last edited by BrUnO XaVIeR; 06-24-2019, 02:16 PM.

  • replied
    Thanks for submitting.Great plugin ,worked wonders on my scene

    Leave a comment:


  • replied
    Originally posted by k3nny View Post
    Hi

    Any idea when the 4.23 version of the plugin is going to be released ?
    I am doing this today.
    Marketplace team's review process I can't tell you how long they take, it's random.

    Leave a comment:


  • replied
    Bumping this- How long before we get the updated version of the plugin for the newly released 4.23 ?

    Leave a comment:


  • replied
    Hi

    Any idea when the 4.23 version of the plugin is going to be released ?

    Leave a comment:


  • replied
    ha, that's what I figured. Will avoid pooling actors into pooled actors. Or breaking eggs ;-)

    Thanks for the clarification on shared pools, seems like I'm on the right track. Appreciate all the help so far!

    Leave a comment:


  • replied
    I do not recommend adding pool components to pooled actors, it's like stepping on eggs.

    A Shared Pool Component exists simply to pack groups of memory together where it makes sense.
    For each class in a shared pool is one less Pool Component you have to attach somewhere else.

    Leave a comment:


  • replied
    Originally posted by BrUnO XaVIeR View Post
    If you want to return a random LevelPart you should make a "switch on int" node with a random int node attached, then call "spawn from shared pool" node using a different class for each node depending of value given by your random int node.

    If random returns <= 1 spawn LevelPart_Base, If random == 2 spawn LevelPart_XX, etc.
    You can do that in blueprint graph.

    That seems to have done the trick, thank you. (my preliminary version of spaghetti BP attached for anyone following along).
    Follow up question: Is there a performance gain to be had using a shared pool and randomizing the class it spawns versus having multiple pools each holding one type of class? Maybe I'm not entirely sure what the main objective of a shared pool would be?

    Unrelated but curious: Can each level part that is part of the shared level parts pool have it's own child pool of actors that are not shared with the parent pool? Put another way can a pooled actor have it's own child pool? (not sharing any pooled actors btw them of course, don't want an infinite loop situation)

    Attached Files

    Leave a comment:


  • replied
    If you want to return a random LevelPart you should make a "switch on int" node with a random int node attached, then call "spawn from shared pool" node using a different class for each node depending of value given by your random int node.

    If random returns <= 1 spawn LevelPart_Base, If random == 2 spawn LevelPart_XX, etc.
    You can do that in blueprint graph.

    Leave a comment:


  • replied
    Hi Bruno,

    Sorry for yet another question, your patience while I sort this out as a BP newbie is really appreciated so far! (hopefully all this helps other people as well)

    I am using a shared pool to hold different level parts for my endless runner (see attached) as each part has different enemies, things to avoid etc.
    Right now the shared pool uses all available actors in a class then moves to the next class in the list and repeats itself.
    I would like it to pick an actor from a template class in the shared pool list at random, is that possible? Am I using/thinking about shared pools completely wrong? Should I just create multiple pools, one for each level part BP and then do a randomization before the spawn nodes?

    Click image for larger version

Name:	sharedpool.png
Views:	1
Size:	11.3 KB
ID:	1645174

    I should also mention, just in case, that I have a level part base class (parent is your pool actor) and all my other level parts extend from that base class. Not sure if that makes things better or worse in this case. Hierarchy looks something like this:

    Pool Actor
    -- BP_Level_Part_base
    ---- BP_level_Part_variation1
    ---- BP_level_Part_variation2
    ...etc

    Leave a comment:


  • replied
    Not always, you just make it possible to happen, so it's good practice to just not make it possible to happen

    Leave a comment:


  • replied
    Originally posted by BrUnO XaVIeR View Post

    They should function normally, just don't add pool components to the child actors that are the same type of pool they are spawned from.
    Right, otherwise we get an infinite loop situation, correct?

    Leave a comment:


  • replied
    Originally posted by rustbucket1971 View Post
    if I have a pool of 10 blueprints and each one includes a child actor does that break the pooling system?
    They should function normally, just don't add pool components to the child actors that are the same type of pool they are spawned from.

    Leave a comment:


  • replied
    Originally posted by BrUnO XaVIeR View Post
    All you need is a proper collision channel setup.
    Make your collision channel ignore itself and set your classes to use that channel by default.
    For example bullets should be in a bullet channel where it's impossible for bullets to collide with each other.

    You can also change a Blueprint's collision channel on pool's begin/end play events.
    Egg on my face, I had my custom collision channel overlapping itself by accident.

    Another question: Let's say I have a blueprint that is part of a pool. If I have a child actor attached to that pooled BP (inside the components tab, not scripted) does that effect performance in any way? In other words if I have a pool of 10 blueprints and each one includes a child actor does that break the pooling system?

    Last edited by rustbucket1971; 07-21-2019, 02:26 PM.

    Leave a comment:


  • replied
    All you need is a proper collision channel setup.
    Make your collision channel ignore itself and set your classes to use that channel by default.
    For example bullets should be in a bullet channel where it's impossible for bullets to collide with each other.

    You can also change a Blueprint's collision channel on pool's begin/end play events.

    Leave a comment:

Working...
X