How to make widget button detonate explosive?

Hello,

I am trying to make a button that I have on the HUD detonate an explosive that is in the world. I have tried all the ways that I know off (my scripting knowledge at this point is minimal.) I cannot seem to figure out how to make the button do anything once it is clicked.

I already have the button on the HUD, the explosive in the world with a radial force and particle system components, and tried patience at this point.

Do I need to script it in the button blueprint or the explosive blueprint? The level blueprint? What nodes should I be using?

Any input (lawl) would be very appreciated.

Thank you,

4Score

Hey, here is some pseudo-node-code for ya:

In the explosive blueprint make a function that would explode it.

In the button blueprint, cast to the explosive actor and then call that function on click.

Boris

This sounds like it would work!

Could you perhaps walk me through making a function that would do so?

thank you,

4Score

Absolutely.
Here is an example. I will be using ExampleExplosive and ExampleWidget.

Here is a simple function inside ExampleExplosive. I just clicked the little + by the functions tab on the left. It would remove that actor from play. There is hundreds of way to actually make it explode, and that would depend on your project. So here is a simple removal script, just add any extra behavior BEFORE the destroy node.

And here is the ExampleWidget blueprint. On click it casts to ExampleExplosive and finds that function.

Oops, here is the second screen.

Thank you! I will play around with that for a while and if I am successful I will mark as answered.

Thank you again!

Okay, I realize I have no idea how to do this correctly. I feel slightly embarrassed but here is what I tried to do and it isn’t working. I imagine it is horribly wrong. Can someone clarify the right way to do it? I took what I found in a tutorial about making explosives. I also read the wiki on functions but I still cant determine how to properly make one.

Thank you,

4Score

I think it’s better that we start with the basics.
If you are running into trouble - deconstruct, simplify.
That’s what I always do.

First. Get the function to work. And have it only do one node, make it destroy itself first.
Once you have THAT done and working, then start adding other nodes.

In the particular screenshot, your sound node doesn’t have a wire going into it, so it will never fire.
I can’t comment on the rest of it, as from the screenshot it seems right, but I don’t know if the rest of the project is correctly set up.

Once you have the function triggering correctly, then start another topic on another particular subject that you need help with.

Oops. Ill connect it and see what happens.

Ok I reconnected it and still nothing. I deconstructed and simplified it to just the “destroy actor” and still nothing.

Here is how it stands:

Could it be the kind of actor or object I am using? I may try it on something else but do you see anything wrong based on these images?

I just tried the same thing (a function that destroys actor) on a completely different thing and still nothing. Maybe its the button? Even though I have an Onclicked event in the blueprint do I still need to bind it? I may try this on a new project and see if maybe something in the one I am currently using is conflicting.

Update Edit: I recreated this simple example in a new project and still nothing. Does it have to do with the playercontroller? a gamemode? I am so lost.

Ok, sorry, that was not your fault. I was over-simplifying.
Here I made a project that works for sure.

So the problem is that it’s tricky to cast to placed actors out in the world. Best way to cast to them is to spawn them in the game mode and then assign a variable to them. So then you can call the variable.

First, I made an explosive barrel BP Class, but didn’t put it in the world. Inside I made the function to destroy it.

Here:

Next, I Spawn the barrel in the world and create the widget. All done in the game mode BP. Once I spawn the barrel actor, I assign it to a variable, in this example I made up the name of the variable to be VarExplosiveBarrel01.

Like this:

Last, I go into the widget, select the button, add the OnClick event. Then in the Graph portion I cast to the game mode and then find that variable and then fire the function.

This is tested and works! Tell me if this helps.

That did it. You’re amazing and I cannot thank you enough