Dynamically creating and binding events.

I am working on a menu structure that accepts a set of arrays to dynamically create sub-menus, and fills them with Buttons.

All of these buttons are supposed to do very similar actions, with different parameters that are decided on construction.

How can I automatically create and bind Events to the IsPressed of these buttons?

There’s a lot of things going on in your second post, it’s difficult to pin down just what you need help with. In your third post, the link you posted is pretty straight forward and fundamental - if you understand event dispatchers. What is happening is a ButtonWidget has a button in it, and that’s all it has, probably along with some identification data. The Onclicked event of the button executes an event dispatcher. The widget that created the ButtonWidget listens - has an event bound - to this dispatcher. You can actually bind to the button, you just need the button reference but I don’t see why you would do that because you can’t identify which button was clicked. The ButtonWidget can give such information.

My first thought is if you really need to create the building buttons at runtime? If you want a building menu like say Starcraft, then all the buttons could be created in the widget and set to be hidden, and then set to visible when appropriate.

I’ve been working a little bit on a project to see if I can figure it out myself, but it’s really just building on the link in your third post.

Basically I have a MainWidget containing the categories and buildings. When Creating the category widgets, they are given a unique ID. The Category widget has an event dispatcher that includes its ID that the Mainwidget listens for.
Then using a widget switcher the correct BuildingWidgets are shown. Widget switcher:
So if the Category with the ID of 1 is clicked, the MainWidget hears that and updated the widget switcher so that the buildings of category 1 are shown.

The MainWidget also creates and listens to the BuildingButtons in the same manner.
The MainWidget is informed that a BuildingButton has been clicked and is provided with the ID, say building type. It then triggers an event dispatcher of its own, which I guess the player controller listens to and passes the ID. The Player controller can then use this ID to say spawn an actor or whatever.

I can share the project, it’s only 19MB. I used the PuzzleExample and the relevant blueprints are: PuzzlePlayerCharacter, MainWidget, BuildingWidget, Categorywidget. Most of it happens in the MainWidget.…X2cF-vEDa?dl=0
Note that I am using some enums and hard coded TMaps to act as my ‘data base’.

Thanks a lot, I am going to take a look at your stuff!

It’s not strictly necessary to create the widget on runtime, but I thought it would be a good exercise, and it would make adding in buttons less of a hassle, since I would just give the new building the appropriate Type/Category/Sort-ID and add them to the Array.
If this gets me to get the hang of how to use some stuff, it’s a net win.

Dude, thanks a ton!
Seriously, you went above and beyond. I am in your debt.

Ironically, it seems I was doing everything right, but fell victim to a bug with the “Create Object From Class”-Node, where it does not update the inputs.
If you either delete the node and put in a new one, or select a different class, and then the right one again, it updates.

That missing Input, combined with the confusing naming in the original example really messed with my mind.

Anyway, it is working splendidly now.