Binding events to dynamically created widgets

So I finally got my head around Blueprint communications using event dispatchers (or so I thought), but I’ve hit a snag.

I have a particular custom class of button. When it is created it contains a variable Page_Link. When one of these buttons is pushed, I want it to send that variable to the Level Blueprint, which can then act upon the contents of the variable depending on what it is.

So in the widget designer for the button I have this:


And then in the Level Blueprint, I initially create a widget which contains one of these buttons, and bind the event to the button:

Screen Shot 2016-02-21 at 22.34.47.png

For demonstration purposes, all this does right now is print to the screen the variable it has received. This works fine with one button generated like this.

The problem comes with when I try to dynamically create another button through a function. As soon as I try to collapse the above into a function, the assignment of the event on so forth disappears. It seems I cannot assign an event to a button created through a function…

There must be something wrong in my approach to Blueprint communications here, but I’m new to this so I can’t figure out what.

Just to be clear, this is what I want:

  1. I want a class of buttons that can be created any number of times, dynamically.
  2. Each of these buttons contains a (different) variable, specified when it is created.
  3. When one of these buttons is pushed, it sends the variable name to the Level Blueprint.
  4. The Level Blueprint then receives this information and acts on it.

What I’m struggling with is the fact that it seems like the assignment (creation of event and binding) seems to be done to a specific button. What I need is a kind of ‘listener’ in the Level Blueprint that just waits for this event to be fired, whatever button it comes from, and receives the variable from the button. It also needs to know what button it came from.

Does that make sense? What is wrong in my approach to this?

Thanks so much for any help.


Right now, you are only binding the initial button. You will need to create a dispatcher (we’ll call it button creation) in your menu widget that you bind to in place of your current binding with an input of ‘your custom/dynamic button’.

In the level blueprint, you will need to pull off of the new ‘dynamic button’ bound event, and then bind event to ‘change menu’.

Begin play → Create widget Menu → Bind event to button creation → Add to viewport
[INDENT][INDENT] [INDENT][INDENT][INDENT][INDENT] Event Button creation ----- Bind event to Change menu[/INDENT][/INDENT][/INDENT][/INDENT][/INDENT][/INDENT]

When you dynamically create your button in your menu widget, call the newly created dispatcher.

It’ll look a little weird since you’ll be binding an event from a bound event, and I think a different approach can make this a lot simpler. (I usually stick widget creation in the PC or the Game Instance).

I can’t quite get my head around what you’re suggesting, and it does seem a little weird/complicated.

Do you have suggestions for a different approach?

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.

Thanks so much for the detailed breakdown – this is really helpful!

Hi, when I bind an event to a created widget I get this error: Error Accessed None ‘CallFunc_Create_ReturnValue’ from node Bind Event to ButtonHOMEClicked in graph ‘EventGraph’ in blueprint AI. I set it up basically the same way as you show but I cant get rid of the error. It still works regardless of the error but I need this to be error free. Any ideas?

Could I get a small picture of the nodes causing the error?

As a guess it might be an order issue and the widget variable is null when the bind is attempted to be set.

I actually figured it out just now. I had one bind event for two created widgets that spawn at different times. Just had to bind it separately and no more error. Thanks though.

Can you please upload the images to another service such as imgur? This website is giving me a 504 error, website is offline. It would be greatly appreciated. Thanks!

I know this thread is old, but this is wonderful. Thank you for taking the time to spell this out, it REALLY helped me solve some stuff I was struggling with.