I have some set of levels. Each level has his own button. Part of the corresponding blueprint:
Define_Level
is my event, to choose level, based on the pressed button.
Am I need create, conditionally, 20 this small constructions for 20 levels? It sounds very bad. I thought about taking information about button from Event, but i don't find paths to do this.
//////////////////////////////////////////////////////////////////
Afterword:
I create class child of button. Now I can set Level_num
directly on my button, It's cool.
Last thing that I cant understand is how I can bind that function to On_Clicked_Event
.
I tried this, but I need set something to Bind_Event_To_On_Clicked
input.
You could make a new bp class which is a child of the UMG button class, call it something like LevelSelectButton.
Give the class a Name
member variable, LevelName
Then define a function there called SetLevel which sets the level using LevelName. And finally in the button, call SetLevel using LevelName on an appropriate event. (I would rather do On Clicked, but if you want it to happen On Released that's up to you).
You will need to create a custom event which makes the call to SetLevel, then use Bind Event to On Clicked to attach that event. Create another custom event called Init that calls Bind Event:
Then in your menu widget(s) which will contain the buttons, you use a LevelSelectButton for each level select button you want, and assign the LevelName of each button as the name of the level it should start.
Finally, you will need to call the Init on each button when the menu is created. One way to do this is to get all the children of the button containers, cast them to LevelSelectButton then call Init on them: