Multiple Dynamite spawned only last one spawned explodes

Okay, so I have done some research into this but none of the answers/info help me fix the issue. I am also pretty new to blueprinting and am doing my best to solve this with the resources I can find, perhaps I am not looking up the correct key words. Any help would be very much appreciated!

Anyways, I have a skeletal mesh actor in the players hand, it is always there just hidden or unhidden given the index value in the array of the gun inventory.

Next, with that weapon in the players hand the player can throw said bundle of dynamite and it will explode, however when there are multiple instances of this dynamite bundle spawned into the world only the last one explodes, is there a way I can set it to all instances of said dynamite so that they all explode given their respective timers? ie player throws one dynamite on a 6 second delay before the explosion, 2 seconds later the player throws another bundle of dynamite, 4 seconds later the first dynamite bundle explodes and then another 2 seconds later the second dynamite bundle explodes.

What I want to know is: Why is only the last instance of the spawned object exploding? I am probably missing something either very simple or just not understanding the problem at all. Thank you for any advice/input into this! I really appreciate it! I am sorry for posting so often!

GIF of the problem in action:

BP script of spawning the object:

Hey @TheSurgeon, looks like things are coming along!
So here’s the fun thing about delay nodes, they delay even looking at what comes after it until the timer is up. Problem is that the reference to your dynamite gets reset to the newest one every time you throw it, so the delay is only going to fire on the last one thrown.

Ways to get around this, and also generally good practice would be to put your explosion logic on the object thrown itself and set it to use it’s own delay. This would mean many things, such as allow for emergent gameplay, clean your player BP, and easily make calls or interfaces to the dynamite from other objects and not just your player.

1 Like

Thanks! Yeah, I spent a good hour putting everything that relates to the explosion logic inside the dynamite bp itself, now I call the event throw dynamite in the player BP which runs the same logic but inside of the dynamite BP. Its a lot cleaner looking now :stuck_out_tongue:

But its still only blowing up one of the sticks of dynamite :frowning:

I was thinking I could set some kind of for each loop with an array that holds all the instances of the thrown actor but when I try that say if I throw 2 dynamite, it will make the same one explode twice now after another 3 second delay (first one blows up after 3 seconds, then after another 3 seconds the same one blows up) not taking into account that they were thrown .2 seconds apart from each other, so technically one should run 1 timer == to 3 seconds and the other one should run another timer == to 2.8 seconds. I’m absolutely sure there has to be something I am missing or just foolishly hooked up wrong.

If you have anymore suggestions I’d really appreciate it! Thanks again! :slight_smile:

New BP script inside dynamite_bp:

EDIT: So for this one it actually adds items to the array but for some reason the for each loop doesn’t iterate through each one causing them each to go through their own seperate loop, will keep trying though!

Oh we’ve got 2 paths here, one I’ll explain why your array system here isn’t working, but secondly I think you’re going very complex for this. I myself have a massive propensity to overcomplicate things. There’s definitely a better way to accomplish all of this. I’m going to make a little dynamite myself so I can show you how I may have gone at it.

So the reason this one is failing as it is, is that you’re making a brand new array every time a new dynamite actor is thrown. You would have to add to an array if you wanted to do that. However that still poses a different problem altogether, once you’re done what will happen is you would either need a separate delay for each, or they’d all explode at once. Hence why I think I can show you a better way altogether.

Alright, so basically if there’s nothing we have to command from the player to the dynamite after it’s thrown, we need to decouple it’s spawning logic from it’s explosion logic. It’s a good programming paradigm to try and keep each function separate and activatable without need for the other, if they don’t have to be together. In this case, it’s the perfect example.

So I strung together a 5 minute concept of how this should be working. It doesn’t have any other logic like your expanding sphere function etc, but it’s basic enough to where you can just string that function in.

Basically, the gun (or player however you wanna do it) will instantiate the dynamite. You have no issue with that, so I’ll just show you how I did mine but won’t elaborate unless you request it. (it’s just a slightly modified version of the FPS template gun for sake of time).

So this is all your firing mechanism should handle if at all possible aside from it’s ammo logic and such.

Now the dynamite, if the delay is encapsulated on the dynamites BP it should always react correctly, and it would be truly fire and forget. For me I decided, “well dynamites spawned, it should start counting down now” so it calls the delay on begin play, then it ticks down and explodes. I use an unattached emitter as well, so when the actor is destroyed it doesn’t take the emitter with it.

After that you’ll just have to port your explosion logic to the end there.

2022-08-17_04-07-24

You’d still have to tweak it a bit to allow for your explosion circle expansion and all that jazz, but if it’s all going to be decided by the dynamites delay you should be able to just apply it.

I know this was a decent oversimplification, so let me know if I missed an important part!

2 Likes

Thank you so much! It works quite nicely, I have a bool set up (since I have the same dynamite in my hand and Id rather it didn’t start the fuse on begin play) that is false by default then when the dynamite is spawned it changes to true; however every single time the very first dynamite thrown does nothing but is spawned but after that it works flawlessly, currently I am trying to find a workaround for this one by changing where the bool turns true. I tried a flipflop but that turns it back to false before it can even get through the branch in the dynamite BP saying its okay to explode.

Anyways thank you for all your help! This is indeed a much much simpler way of handling this than what I was trying to do initially!

Awesome! So if you still wanna hear me ramble about best practices, having the dynamite physical before spawning complicates things a bit, but you could just swap out your begin play for a custom event (an interface possibly?) that’s triggered when it’s thrown, and voila should solve any issues if you followed the structure I had. (I think), let me know if you have anymore questions. Since this one is solved, you’re also free to post a new one to help the community search system find our answers better for others!