Announcement

Collapse
No announcement yet.

Plugin Object Pool Component

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

    [SUBMITTED] 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.
    | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

    #2
    ok, i don't know C++, I'll wait for your plugin

    Comment


      #3
      This is actually very useful for a lot of things, definitely worth $10 I'd say.

      Hope it gets put on the marketplace ASAP!

      Good job
      Why do all programmers wear glasses? Because they can't C#

      Comment


        #4
        I have just updated original post, with Marketplace release date, and the tutorial on how to use the plugin
        | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

        Comment


          #5
          Awww, I really like "quality of life" plugins like this. Could you please update us when it's ready to be thrown money at?
          Youtube Channel

          Comment


            #6
            Originally posted by BoredEngineer View Post
            Awww, I really like "quality of life" plugins like this. Could you please update us when it's ready to be thrown money at?
            [MENTION=12960]BoredEngineer[/MENTION]
            Marketplace released this today:

            https://www.unrealengine.com/marketp...ct-pool-plugin
            | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

            Comment


              #7
              Thank you!
              Youtube Channel

              Comment


                #8
                Essential plugin but having crash-issue with 4.14. Seems like if the pool have some destroed actors, then the editor crashes when "empty object pool"-node is used, the related blueprint (that have the pool) is destroyed or play in viewport session is ended.

                Comment


                  #9
                  Originally posted by SaOk View Post
                  Essential plugin but having crash-issue with 4.14. Seems like if the pool have some destroed actors, then the editor crashes when "empty object pool"-node is used, the related blueprint (that have the pool) is destroyed or play in viewport session is ended.
                  Thanks, I will check this right now.
                  Just keep in mind that pooled objects are not supposed to be destroyed (destroy the pool owner instead), but it shouldn't crash because of that, I will see where the mistake is.


                  Edit:

                  [MENTION=50574]SaOk[/MENTION]

                  Thank you for finding this issue;
                  I have found the crash reason, I've fixed it and will submit to Epic as soon as I can.

                  The thing is, I forgot about one thing: to check if any of Pooled Actors are marked by the engine as Pending Kill before I tell the Pool Component to be empty.
                  The result is that once you destroy a pooled actor, it is not immediately gone... It is marked as pending kill until GC is able to collect, but there's a pointer in the Pool holding reference to the destroyed Actor and once you use the 'Empty Pool' in this case you are actually calling Destroy() function 3x on an Actor that is not valid anymore.
                  I just had to check if the pooled Actors are valid at low level, just one line of code inside the Empty Pool function.
                  | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

                  Comment


                    #10
                    Great to hear , thanks for the instant response. Cant wait to try the upcoming update.

                    Was using the pool for bullets. Tried to prevent those getting destroyed, but seems those ended up to z world removal.

                    Comment


                      #11
                      I've sent the files to Epic already; I have to sit and wait now.


                      Edit:

                      Fix is already on Marketplace.
                      Last edited by BrUnO XaVIeR; 02-10-2017, 07:21 PM.
                      | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

                      Comment


                        #12
                        Does this plugin support c++ Actor ? And how to pool the particles?
                        Last edited by liuwei; 02-12-2017, 11:48 PM.

                        Comment


                          #13
                          Hi Bruno! Great plugin!

                          Quick question: To get an actor spawned from the pool to tick i have to enable ticks in the On Pool Begin Play? It was the only way i could get ticks to work. (and probably a stupid follow up question; should i then disable ticks before returning it to the pool? )

                          Comment


                            #14
                            I'll definitely be buying this!! Very excited for the Pooled Characters and pawns!

                            Comment


                              #15
                              Originally posted by gotgrassct View Post
                              I'll definitely be buying this!! Very excited for the Pooled Characters and pawns!
                              Thanks, Character support will come soon; I just hsve to deliver paid work first :s
                              | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

                              Comment

                              Working...
                              X