Binding events to dynamically created widgets

I’ll post some pictures for a simpler method. I would post a video, but I am on terrible dsl right now.

I’ll include more in-depth steps just in case something is missing + for anyone who references this later =).

Step 1:
First we’ll create our special button (I named mine U_SpeciaButton). I deleted the canvas panel and have made the button the main parent, and have added a text box within for flair.


Step 2:
I have created an Event Dispatcher in the same widget called “Clicked!”. And I have created a random int variable on Event Construct to show that this button is unique (Unless rng gods hate us and ruin the demo)

Step 3:
Now for the Menu widget (I named mine UI_Main) I have created a vertical box to store the buttons that will be added at runtime. I have also checked the Is Variable box to enable referencing this in the blueprint.

Step 4:
In the Menu widget the Construct event is creating the buttons (This can be on any event really) and I am binding each buttons “Clicked!” Event to the Menu’s “Button Clicked =)” Dispatcher. This will hopefully make sense in the last picture if isn’t already.

Step 5:
In the Player Controller, we have our Menu widget created and we have bound our top-level “Button Clicked =)” dispatcher.

Step 6:
Profit =)

You can think of this method as bubbling up. It helps me visualize how it all works.

9 Likes