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?
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.
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.
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.
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.
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.
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.