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
    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:


  • replied
    Originally posted by skydashstudio View Post
    I got a problem. Sometimes, my enemy is destroyed immediately when I start level.
    After trials and errors, I realized event begin overlap of my bullets are fired when a pool is initialized. Their location are 0,0,0

    https://youtu.be/BAmKjlgZQ3k
    (More info in this video.)

    To fix this glitch. I add "event begin play. -> set actor location = player pawn location." to my pooled bullets.
    I had the same issue with my overlaps all triggering at once. I use begin play and moved them to a coordinate (z = -1000) where I knew they wouldn't trigger. Worked like a charm, thanks for figuring that out!

    Given everything in a pool seems to spawn at 0,0,0 this is the only workaround I have found, is there a way to delay events or something? I tried unchecking start on tick and auto initialize but that didn't work.

    Leave a comment:


  • replied
    The fix should be available on Marketplace now.

    Leave a comment:


  • replied
    No worries, thanks for the quick support.

    Leave a comment:


  • replied
    Originally posted by SaOk View Post
    After latest plugin update, pawn-pool component dosent seem to be working correctly. If trying to create spawn from pool from blueprint using that class as parent, the node connection gets deleted instanlty and you cant reconnect it even it shows green. Blueprint compile with spawn pawn from pool cause editor to crash.
    Can you show me a screenshot of node and component and send me a crash log?

    _____

    Edit:

    Oh okay, I did a mistake.
    In Pawn K2Node_ there is this:
    Code:
    PoolPinName(TEXT("ObjectPool"));
    That is wrong, the pin name is "PawnPool"... That's why you get a crash.
    I messed up, sorry! I fixed the mistake on K2Node_SpawnPawnFromPool and sending to Epic to update files on Marketplace

    Leave a comment:


  • replied
    After latest plugin update, pawn-pool component/Pool Pawn dosent seem to be working correctly. If trying to create spawn from pool, the node connection gets deleted instanlty and you cant reconnect it even it shows green. Blueprint compile with spawn pawn from pool cause editor to crash.
    Last edited by SaOk; 06-29-2019, 08:06 AM.

    Leave a comment:


  • replied
    Okay... based on changes for the 1.9.0 plugin I am submitting for review today, for Unreal 4.22+, I rewrote the whole original post covering a lot of things that was not mentioned previously:

    https://forums.unrealengine.com/unre...ent#post104929

    Leave a comment:


  • replied
    Moved into the plugin from a project, a custom component to fire projectiles along Splines components...
    Now need documentation :s


    Leave a comment:


  • replied
    Originally posted by BrUnO XaVIeR View Post
    Video tutorials are always welcome

    From my POV is difficult to see "things that I take for granted", but new devs find difficult dealing with.
    Yeah, I could totally see that which is why I thought maybe a tutorial written by a newb for other newbs might provide the missing context. (that or I'll end up making things worse!)

    Leave a comment:


  • replied
    By the way, I have scheduled this next sunday to review these same 10 pages of questions and add relevant info into the main thread.

    Leave a comment:


  • replied
    Video tutorials are always welcome

    From my POV is difficult to see "things that I take for granted", but new devs find difficult dealing with.

    Leave a comment:


  • replied
    Got it working! Phew! (Bruno, you can disregard that error message request for help)
    Really nice plugin, very much appreciate you putting this together now that I finally grasp how it works.

    That said...some constructive advice? It could really benefit from better documentation, scanning through 25 pages of forum posts to figure out my issues wasn't the easiest way to learn something. I know it's not fun to write out instructions but some really important stuff about projectiles, shared pools, etc. is all buried 7-8 pages deep in this thread. In the long run it would probably save you a lot of time dealing with support issues from noobs like myself.

    Hopefully that didn't come off as too negative because this thing literally saved my project and I owe you. As a way of paying it forward would anyone be interested in a quick video tutorial so they can grasp the basics? Let me know and I'll try and put something together!

    Leave a comment:


  • replied
    Yeah I have the 1.8.2 version of the plugin and it was installed on 4.22.3 so that would explain why 4.20 was crashing.

    I hate to be that guy who is a pain in the *** but the 4.22 project you linked doesn't seem to want to load, error attached. Would it just be easier for me to create a new project and import the content from your zip file?

    Attached Files
    Last edited by rustbucket1971; 06-19-2019, 04:50 PM.

    Leave a comment:


  • replied
    Here is demo project for Unreal & plugin version 4.22:

    https://www.dropbox.com/s/8urovvv6c7...E4.22.zip?dl=0

    Leave a comment:

Working...
X