So, I’m making a BP that change the material of an actor in my level in game.
I would like to know if its possible to create automaticaly a number of buttons equal to the number of materials i add to my array:
In this case you can see in my detail window → 1 - material index in the actor that I want to change; 2- Selection of the actor in my level ; 3 - four materials in my array that i could choose in game, could be more, could be less.
In my widget you can see that I manually set up 4 buttons to do the action of changing the material, its a simple setup of 4 buttons, no big deal.
I would like that the numbers of buttons in my interface would add or subtract equal the numbers of materials that i have in my array on the BP.
So, its possible to do that ? Basically, to add “N” number of buttons automatically to my widget ?
yes, use a horizontal box as a parent, in the box have an array of materials. for each material create a button widget and add to horizontal box. pass through the index on the loop. when the button is pressed call an event passing back the button index.
Do you know any tutorial or could send me a image?
I’m not being able to create the button in graph, that’s mostly my problem, and I’m not finding anything in internet to help me
another widget creates a bunch of our custom buttons, feeds each a material from the array, adds them to a Horizontal Box and registers a dispatcher call:
Note how we do not need to faff around with indexes; each button knows the exact material it’s supposed to assign to the mesh. Less room for errors! As a bonus, if you ever want to change how buttons looks like, you need to change 1 button only rather than chase around a dozen menus and change 50 buttons.
and sets up a dispatcher call
This last part can be done even better, you could have an event inside the actor that owns the primitive component and directly bind to that instead. Do tell if you’re interested.
The actor holds the materials and the widget changes the sphere’s mesh? In which case this can be set up better. But the previous suggestion could work OK, too!
Sry, Im kinda newbie in this. So its a functionality to change material in game, its a BP that refers to an actor in my level, its not a component in my BP. Here is how it works:
Thank you very much, getting familiar with widgets, do you know any good tutorials on then ?
And you know if its possible to use the image thumbnail of the materials as the image in my buttons ?
The thumbnails will not make it into the final packaged product (unless something changed recently) so I’d avoid doing that. You could have a widget display a dynamic UI material and feed it a texture parameter. Or set up a render target to generate images. Or capture the images by hand.
getting familiar with widgets, do you know any good tutorials
It might be too broad of a topic to just sit down and watch a dozen generic tutorials. When looking for answers, try searching for something more specific instead. Once you have a half decent understanding of how UMG works in general…
you could try looking up a bunch of tips & tricks to fill in the gaps.