I’ve made a dynamic array of buttons inside a scroll box (I’ve made a button widget for this and its a query that retrieves button name from a table), and i’ve want that when i click a button, it will print its button name. What am i doing wrong? im new to unreal…
Binding an event is easy. Create your OnClick event. Now you can call “Bind Event to On Clicked” on each of your buttons. The problem you have is identifying which button was pressed.
The usual way is to create a custom widget with a button in it with the Button Name as a public variable. Then you create an event dispatcher “OnClicked” that has Name as an input. You’d click the ‘+’ icon for the button’s On Click event in the designer to call the dispatcher event with the button name. In your original blueprint, you would create these custom widgets instead of buttons and then bind to the OnClicked dispatch event. These event would provide the name. And you can print it.
Would you be able to elaborate on this please? I can’t seem to find a way to set the button name as a public variable.
i think you may mean ‘InstancedEditable’ and ‘ExposeOnSpawn’
Well, I’m not sure you even need a public variable. It’s unclear exactly how you’re identifying which button has which name. It’s also unclear what you mean by “print”. Are you logging the name, displaying it on the button itself??? We don’t know.
So I’ll give you an example case where we set the names ourselves.
Create a new widget blueprint. Drop a button on it.
Click on the “Graph” button at the top right.
Notice on the left, there’s a section called VARIABLES.
Click the + icon with the circle around it that’s next to VARIABLES.
Give it a name of Name. And a type of String.
This variable is currently private. To make it public, you click the little eye icon to the right of the little bell icon.
Now it is public. This means other blueprints and widgets can read and write the Name property. You can even set it in the designer of another widget if you drop buttons in your canvas or whatever else in designer.
But since it’s a custom widget, OnClick doesn’t exist. In fact, no event exists on your widget. So let’s create one.
Click the + icon next to Event Dispatchers.
Call it OnClick.
Keep OnClick selected.
Now look to the right at the details panel. The first section should be called “Inputs”. On the header where it says “Inputs”, there’s a big + button to the right. Click the + button.
Name the input “Name” and give it a type of String.

Now select your button in the Variables section. On the right panel that says “Details”, you should see a bunch of events at the bottom. Click on the + for On Clicked. This is the click event for your button. We will propagate it down to your widget as a whole.
Now drag your OnClick Event dispatcher onto your graph and select Call. Connect the On Clicked event to Call On Click node.
Now we need to pass in the name of your button.
So drag the Name variable onto your graph and select Get. Connect it to the Name pin of the Call On Click node.
Now, when you use your custom button widget, you can set a name on it and you bind an event to it that will give you the name.
How you set that name and what you do with the event is up to you.

