Call a button's Click event in blueprints

Suppose I have a 5 custom UMG widgets, all of which has a Button component with their own OnClick event that does something special.

Now I have a reference to a Button component belonging to one of these 5 custom widgets. How do I invoke the respective OnClick event? I can’t seem to find a Call OnClick function anywhere?

1 Like

Hello Wufasa,

Could you explain what you’re trying to accomplish? The OnClick event isn’t something that you would call manually, it’s something that is already set to be triggered whenever the button is clicked. If you need to add any more logic to the event, you’ll need to do it where the event is declared or have the OnClick event call a custom event that you have created.

Hi Matthew,

Thanks for your reply! I just wish to programmatically (in blueprints) call the OnClick event from a button reference. Since I am not directly deciding which button was clicked based on which button the mouse is over (actually I’m determining which button was pressed based on which button is closest to a certain actor). I suppose the only way to accomplish this is for all my custom widgets implement a Clickable interface and call that from the reference (I would suppose buttons already implemented an interface with the OnClick event)?

I don’t think the OnClicked event is the best event for you to use here as it is only triggered when directly clicking the button. It may be more useful if you use a Left Mouse Button input event instead and then check the proximity to decide which button to trigger. You can then create custom events inside of these buttons that you can call after determining which button to trigger.

Super simple.

All you need to do is assign a custom event to the function on top of it’s OnClick. Then use that reference to call the custom event.

Clicking the button will activate the print.

Calling TriggerSuperAwesomeFunction will activate the print.

Both do the same thing, custom event can be called from the reference.

1 Like

Hmm ic… I was hoping that I could just directly call the OnClick event so that I won’t have to create a new button widget just to expose said OnClick event. But thanks for confirming that creating a new button widget is the best approach!

It wonder me when click effect from 3d world position , how to make an actor interactive to Ui widget button like mouse ? I need it for my kinnect game.

But how do I do that when the function I want to run is private? For example if i want to call a private function not “PrintString”?
Thank you!

Instead of binding event to “OnClicked”, you can call Event Dispatchers on click, and bind events to them.


1 Like

There are many ways. If you want them all to do something different, one way (of many) is to create a blueprint interface containing a function, let’s name it “HandleClick”, and then add that function to each UMG Widget class you create.

Then you can implement that interface function in all your widgets, and both hook a call to that interface function up to the actual click event node, and also call the function from anywhere that has a reference to your widget.

You don’t have to use an interface, but it makes it so you don’t have to cast to a specific widget class in order to call the HandleClick function.