Announcement

Collapse
No announcement yet.

Plugin Object Pool Component

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

    #76
    Originally posted by RexVex86 View Post
    sent you a pm, but decided to send it here in case anyone else had same problem..

    Hello Bruno,


    I would greatly appreciate some help implementing your object pool.

    I read through your instructions but I am not sure I am using it correctly.


    1. Create an object pool by clicking in asset browser, selecting synaptech and then object pool and named it BP_Projectile_Pool. OK

    2. Go into (in my case) redtrooperbullet.blueprint and reparent it to (S)Pool Actor. OK

    This is where I got lost:
    3. Create a new blank actor? and insert the BP_Projectile_Pool component into it? Do I have to place this actor into the level? In this new blank actor, I should select my redtrooperbullet.blueprint and select "200" as the pool size... Am I doing this correctly?

    4. How can I get reference from the pool inside the character that is shooting this bullet (before I just had to spawn a bullet actor without any references...).

    Are there any other steps I missed?


    Thank you!
    Reinaldo
    An Actor somewhere in the Level must have a pool component attached; I usually add the component to the gun.
    Then that Component manages the class of the pooled projectile you've created on Asset Browser, spawn/return, etc. there are some nodes you have to use instead of the regular Spawn Actor or "Destroy" node to make use of the pool component correctly.
    There is a demo project with a pool component and a pooled Actor here: https://www.dropbox.com/s/z2php8xxv7...oject.zip?dl=0

    You don't have to reference anything; the Pooled Actor always knows which Pool Component is its owner. they communicate automatically in C++ without requiring you to setup this stuff.
    On the Gun you'll want to get drag a ref of the Pool Component to call "Spawn from Pool" node, but that's pretty much all for it.
    On the Pooled Bullet you'll want to use the "Return to Pool" node when you want to destroy it.
    Last edited by BrUnO XaVIeR; 06-14-2017, 02:17 AM.
    | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

    Comment


      #77
      Hi!
      I saw you use separate begin/end-play events. I was wondering if you had looked into resetting the actor and reusing the standard events. If so, did you get very far?

      I would assume the goal of pooling is to get around all the stuff that happens before BeginPlay is called, so I know a full reset of the actor would be bad. I was just wondering if there was some way to just let a pool use BeginPlay and EndPlay normally. Or if you had gotten anywhere at all trying to find a way.

      UPDATE: I think I figured out a way to do it. At least, it looks like its working. If you would like to reuse the Begin/End Play events instead of relying on your own events, I'd be happy to share. It's a bit hacky -- in the sense that if the engine changes it will break this solution. But it doesn't look like that part of the engine is changing any time soon. We should be trying to get an otherwise innocuous change into the engine source but for now I think you'll like what I came up with.
      Last edited by Jin_VE; 06-19-2017, 04:52 AM. Reason: Came up with a solution

      Comment


        #78
        Bruno, I successfully implemented the pool component into my hero character (all of my firing is done from inside my character)...

        1. 1 Issue I have is that your Pooled Projectile (that replaces Projectile Movement) does not allow a "Set Homing Target Component"... why is that? That is something that Projectile Movement allows...

        2. Also, how can I expose the parameters I need from the construction script (before I would allow properties such as speed, damage, controller id, to be exposed on spawn )

        3. Spawning bullets with physics enabled also seems to cause a problem where the bullets dont render - but they definetly get spawned and hit things (I have audio, phsyical and damage cues to show that).
        Taking off the physics renders the bullets properly.. but I want bullets with physics enabled so that is not a solution for me... do you have any of this on your end or is this just me?

        4. I am still a bit confused by the following: I named my pool blueprint the same as yours it is called Bp_Projectile-Pool and I use it as a component inside my hero character, who then calls it whenever he wants to spawn the bullets - but I am not sure if once I make that component blueprint (bp_projectile-pool) Do I ever need to change anything in that specific blueprint, or do all the changes need to be done inside the actor that is the current owner of that component(in my case my hero character has the object pool component, so all the changes like template class, pool size, thats all done inside his blueprint and never in the actual bp_projectile-pool blueprint?).. I have been making the changes in my hero character and that has worked, but just wondering if this is the workflow you intended?
        Last edited by Imagine-Games; 06-19-2017, 01:07 AM.

        Comment


          #79
          Originally posted by Jin_VE View Post
          Hi!
          I saw you use separate begin/end-play events. I was wondering if you had looked into resetting the actor and reusing the standard events. If so, did you get very far?

          I would assume the goal of pooling is to get around all the stuff that happens before BeginPlay is called, so I know a full reset of the actor would be bad. I was just wondering if there was some way to just let a pool use BeginPlay and EndPlay normally. Or if you had gotten anywhere at all trying to find a way.

          UPDATE: I think I figured out a way to do it. At least, it looks like its working. If you would like to reuse the Begin/End Play events instead of relying on your own events, I'd be happy to share. It's a bit hacky -- in the sense that if the engine changes it will break this solution. But it doesn't look like that part of the engine is changing any time soon. We should be trying to get an otherwise innocuous change into the engine source but for now I think you'll like what I came up with.
          This is dangerous, so I don't do it.
          | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

          Comment


            #80
            Originally posted by RexVex86 View Post
            Bruno, I successfully implemented the pool component into my hero character (all of my firing is done from inside my character)...

            1. 1 Issue I have is that your Pooled Projectile (that replaces Projectile Movement) does not allow a "Set Homing Target Component"... why is that? That is something that Projectile Movement allows...
            This have never been requested, so it's probably not exposed, I will have to check why is this way in the plugin.

            2. Also, how can I expose the parameters I need from the construction script (before I would allow properties such as speed, damage, controller id, to be exposed on spawn )
            Check on properties "expose on spawn" checkbox, on your blueprint. They show up in the spawn node after that.

            3. Spawning bullets with physics enabled also seems to cause a problem where the bullets dont render - but they definetly get spawned and hit things (I have audio, phsyical and damage cues to show that).
            Taking off the physics renders the bullets properly.. but I want bullets with physics enabled so that is not a solution for me... do you have any of this on your end or is this just me?
            There's something wrong with your SpawnOptions struct if this happens; check the options you use, Unreal is a little annoying with these settings and they cause this kind of problem when misused.

            4. I am still a bit confused by the following: I named my pool blueprint the same as yours it is called Bp_Projectile-Pool and I use it as a component inside my hero character, who then calls it whenever he wants to spawn the bullets - but I am not sure if once I make that component blueprint (bp_projectile-pool) Do I ever need to change anything in that specific blueprint, or do all the changes need to be done inside the actor that is the current owner of that component(in my case my hero character has the object pool component, so all the changes like template class, pool size, thats all done inside his blueprint and never in the actual bp_projectile-pool blueprint?).. I have been making the changes in my hero character and that has worked, but just wondering if this is the workflow you intended?
            It's your choice, I also prefer to control things in the character blueprint too; works fine this way.
            | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

            Comment


              #81
              Bruno regardin topic 1. what is funny is your pool projectipe has the boolean is homing projectile and the float homing projectile magnitude but without this one component "set homing target component" it will never home towards anything... would you ever consider "fixing" this or else no one will ever be able to use your object pool with homing projectilesm.m

              Comment


                #82
                Yes, I add to my to do list.
                | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

                Comment


                  #83
                  regarding # 2. I know how to make my blueprint expose on spawn lol(im not that much of a noob).... what I don't know is how did you get your projectile to appear there in your blueprint instead of casting to it like you where doing before(you just showed the photo showing your exposed variables but you didnt show how to expose them)... I also checked your demo project, and you are still using the old way - you spawn actor from pool without showing any expose on spawn options...

                  Also for #3, it is in the spawn options that I am enabling and disabling physics...

                  I apologize, I know for 10$ you are doing a hell of a lot but I just think some better explanations for semi-noobs for me would be optimal, especially as noobs start getting into serious development they will definetly need this plugin for performance... obrigado

                  here is a foto showing no expose on spawn options and the 2nd one with my original bp being spawned normally with the exposed options
                  Click image for larger version

Name:	crop1.png
Views:	1
Size:	115.7 KB
ID:	1129935
                  Click image for larger version

Name:	crop2.png
Views:	1
Size:	81.5 KB
ID:	1129936

                  Comment


                    #84
                    Originally posted by RexVex86 View Post
                    regarding # 2. I know how to make my blueprint expose on spawn lol(im not that much of a noob).... what I don't know is how did you get your projectile to appear there in your blueprint instead of casting to it like you where doing before(you just showed the photo showing your exposed variables but you didnt show how to expose them)... I also checked your demo project, and you are still using the old way - you spawn actor from pool without showing any expose on spawn options...

                    Also for #3, it is in the spawn options that I am enabling and disabling physics...

                    I apologize, I know for 10$ you are doing a hell of a lot but I just think some better explanations for semi-noobs for me would be optimal, especially as noobs start getting into serious development they will definetly need this plugin for performance... obrigado

                    here is a foto showing no expose on spawn options and the 2nd one with my original bp being spawned normally with the exposed options

                    On your Pool Component's "Template Class" you have to set it to "NewPBullet1", this is why you don't see your exposed properties.
                    After you do that the spawn node will automatically cast and your exposed properties will show on node. If you need to cast then it's wrong.
                    Check this on your Details panel, after I set the Template Class to my Blueprint class then I don't need to cast anymore and the exposed properties show up on the node:



                    | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

                    Comment


                      #85
                      1. so you added the pool component to the bullet's bp(pool_bullethell2) itself AND the actor that is going to spawn the bullet from pool (in my case the character) I guess in your case the weapon.. they both have the bp_projectile-pool (object pool component) in them as components???

                      I really don't get it, it seems like the instructions from the 1st post and what you are doing here is completely different, or maybe im just completely lost LOL

                      Comment


                        #86
                        No; the bullet is a class child of "PooledActor" which must be selected as a "Template Class" in the Pool Component.
                        The Pool Component is an OBJPool component class.

                        It isn't working for you because you are making the Pool Component spawn the default "PooledActor" class which comes with the plugin instead of selecting your correct class child of a Pooled Actor to be the Template Class used by the Pool Component.
                        It's very clearly explained in first post on the "How to use" section: https://forums.unrealengine.com/show...l=1#post642602

                        If you attach Pool Component to a PooledActor you'll make an infinite loop and Unreal may crash.
                        Using "PooledActor" as Template Class does nothing, this is a base class and has no mesh; you simply have to create an Actor, set its parent to be PooledActor derivative then on Pool Component pick this Actor to be the "recipe" of the pool, this is what the Template Class param is for.
                        | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

                        Comment


                          #87
                          Hi, I would like to use this plugin in C++.

                          I created a PoolManager that dynamically generating UCharacterPool by custom character types.
                          There are 2 functions "PullActor" and "ReturnActor" in UCharacterPool. But PullActor is deprecared after 4.15.
                          How to pull a APooledCharacter from UCharacterPool in C++ now? Should I call "BeginDeferredSpawnFromPool" directly?

                          Another question: My Character animation is using Animation Blueprint. Is there any way to reset animation when pull from pool?

                          Comment


                            #88
                            Originally posted by elliotlo View Post
                            Hi, I would like to use this plugin in C++.

                            I created a PoolManager that dynamically generating UCharacterPool by custom character types.
                            There are 2 functions "PullActor" and "ReturnActor" in UCharacterPool. But PullActor is deprecared after 4.15.
                            How to pull a APooledCharacter from UCharacterPool in C++ now? Should I call "BeginDeferredSpawnFromPool" directly?
                            Yes, in this case you'd want to call the "Begin Deferred Spawn" function:
                            Code:
                            UObjectPool::BeginDeferredSpawnFromPool(const UObject* WorldContextObject, UObjectPool* ObjectPool, const FPoolSpawnOptions &SpawnOptions, const FTransform &SpawnTransform, ESpawnActorCollisionHandlingMethod CollisionHandlingOverride, AActor* Owner, const bool Reconstruct, bool &SpawnSuccessful)
                            After you're done with the spawn process, you also have to call in C++ the "Finish Deferred Spawn" function to conclude the spawn process:
                            Code:
                            UObjectPool::FinishDeferredSpawnFromPool(APooledActor* Actor, const FTransform &SpawnTransform)
                            Both return a pointer to the spawned actor, but you should call the Finish one only after checking that the pointer from Begin is valid; after many collision checks the engine may decide to not spawn the Actor depending on your collision options and then the returned pointer may be invalid, in this case Actor->FinishSpawning(SpawnTransform); will not execute.




                            Originally posted by elliotlo View Post
                            Another question: My Character animation is using Animation Blueprint. Is there any way to reset animation when pull from pool?
                            You can subscribe a function to the "On Pool Begin Play" and "On Pool End Play" events of your PooledActor, then in these subscribed functions set a param that is read by the AnimBlueprint which would make AnimState return to its default value.
                            The events are these in Pooled class:
                            Code:
                            	/// Event called every time this Character is spawned from the Pool.
                            	UPROPERTY(Category = "Object Pool", BlueprintAssignable)
                            	FOBJP_PoolEvent OnPoolBeginPlay;
                            	
                            	/// Event called every time this Character is sent back to the Pool.
                            	UPROPERTY(Category = "Object Pool", BlueprintAssignable)
                            	FOBJP_PoolEvent OnPoolEndPlay;
                            	
                            	/// Event called every time this Character is spawned from the Pool.
                            	UFUNCTION(Category = "Object Pool", BlueprintImplementableEvent)
                            	void EVENT_OnPoolBeginPlay();
                            	
                            	/// Event called every time this Character is sent back to the Pool.
                            	UFUNCTION(Category = "Object Pool", BlueprintImplementableEvent)
                            	void EVENT_OnPoolEndPlay();

                            Edit:

                            Those events are automatically executed, you don't have to call any of them; just subscribe a function to them; example:
                            Code:
                            OnPoolBeginPlay.AddDynamic(this,&AMyPoolCharacter::ResetAnimations);
                            Last edited by BrUnO XaVIeR; 07-25-2017, 01:19 AM.
                            | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

                            Comment


                              #89
                              @BrUnO XaVIeR

                              I'm having an issue when the projectile is spawned from the pool, it won't move but if I spawn it from the traditional 'Spawn Actor', it moves as it should do. Is there an obvious step or call I should be making?

                              Comment


                                #90
                                Originally posted by Cerebros View Post
                                @BrUnO XaVIeR

                                I'm having an issue when the projectile is spawned from the pool, it won't move but if I spawn it from the traditional 'Spawn Actor', it moves as it should do. Is there an obvious step or call I should be making?
                                Issues like this is always due to the collision/physics settings you're using when spawning your projectile.
                                Make sure you use correct physics settings on your spawn options.
                                | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

                                Comment

                                Working...
                                X