Hi,
I have an actor with a list of clothes. I want to create a menu where user can select the clothe.
I have a created Widget on which I am programatically creating one button per close using a for loop.
In the same construct, right after adding the button, I am binding to a OnClicked event :
When I add this button, I know which clothe correspond to that button and I’d like to pass the information
My issue is that all button are bind to the same Event, so I cannot call the method to set up my character clothe based on the button clicked…
Is there a way to pass an argument to the Event Bound ?
Everynone
(Everynone)
March 16, 2024, 10:24am
2
Do it OnInitialised
instead. See the green bit below.
Is there a way to pass an argument to the Event Bound ?
Not to the native one. Add your own dispatcher with any data you want and have the button click call it:
When binding, bind to that dispatcher instead that of the native button’s. Another, slightly more nuanced way is to wrap a button in a user widget, expose a unique ID variable, populate it with data, and have it dispatch that ID.
Thanks for the fast answer. But I don’t fully get it.
First I cannot add a OnClicked Button 331 like you, as this button is not a variable, it is programmatically added.
Then I don’t have on initialized.
and even if I have it, I really want to take action when the button is clicked, not initialized.
I’ve created my own dispatched, and was able to add the correct parameter, but I’m lost in what I need to do with it.
For now I’m stupidely adding it like this, but I’m never using the argument / input… so that’s useless
It would be more logical to listen to that event in my actor blueprint… so i’ll read more on dispatcher
Everynone
(Everynone)
March 16, 2024, 11:25am
4
For now I’m stupidely adding it like this
Heh, that’d work in a pinch!
You could associate dynamically created buttons with data in a map, but that’s just a workaround.
Make the button into a User Widget and feed it data as it spawns.
a widget with just a button, dispatcher and some ID (enumerators would work great if you have fewer than 20 buttons) You already have this part. Instead of ID push in the struct, and have the widget send the mesh.
instead of creating native buttons, create your fancy ones:
You only have one event, but every buttons can do something different.
You can expose more data like this so you get configurable buttons.
1 Like
Everynone
(Everynone)
March 16, 2024, 11:36am
5
I mean:
You can work with this. Push this struct into the button user widget.
Everynone
(Everynone)
March 16, 2024, 11:45am
6
This is how I’d actually do it:
Clicking a button fires a custom event in the player BP, delivering the mesh the button obtained from the struct array.
This is how I’d actually do it:
But I’d use soft references instead. Unless the scope is really small.
1 Like
That won’t work, I get the error I was getting before opening this thread : it will be the skeletal mesh of the last loop that will be added (not the skeletal mesh associated to the button). If i click on the 1st button, I’ll get the skeletal mesh of the 3rd button…
I forgot to mention that this inventory of clothes is dynamic, so I cannot hard code the integer like you do.
I’ll look to your suggestion with custom button.
Everynone
(Everynone)
March 16, 2024, 11:50am
8
I did not hard-code anything, the ID is dynamically added as the buttons spawns. Have a look at the exposed variables. Push the data into the widget:
Either the entire struct or just the mesh.
I was refering to the previous answer, more particularly this :
Your switch block has a static number of pin
I need to look to all your new answer in detail now, it looks good .
Thanks a lot for the time you took.
Everynone
(Everynone)
March 16, 2024, 11:55am
10
That’s why I suggested using enumerators. This was just an example. Besides, send the skeletal mesh directly, then there’s no need for ID.
This is how I’d actually do it:
in the player:
[image]
in the custom button:
[image]
when you create buttons:
[image]
Clicking a button fires a custom event in the player BP, delivering the mesh the button obtained from the struct array.
This is how I’d actually do it:
But I’d use soft references instead. Unless the scope is really small.
Working perfectly !
Only thing I would add to clarify for other reader is that the Custom Event Dispatcher is created on the custom button
First time I got an issue solved in this forum, don’t know how to mark it as the answer. I found this post but it didn’t help :
How do i mark a topic “Resolved”? - General / Feedback & Requests - Epic Developer Community Forums (unrealengine.com)
Everynone
(Everynone)
March 28, 2024, 9:08am
14
When you start a thread you either get to choose a question or a discussion .
Discussions can’t be solved, it seems. We’re stuck here in a loop, forever discussing. Or it will auto close in a month.