Its possible to create a "N" number of buttons automatic in a widget ?

Hello guys,

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 ?

Thanks !

1 Like

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.

get the index from the array and assign material.

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

You can create native buttons but that’d be awkward to use.


Consider the following instead:

  • a User Widget with just a native button, a material variable and an Event Dispatcher:

  • 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.

1 Like

It worked! Thank you very much
How can I change how it looks? Is it in the Button Widget ? Or inside my horizontal box ?

What you mentioned about an event inside the actor, I would like to see, even though i didn’t understand very well what you meant by that


Its getting squished, even thought I did a very large horizontal box

Yes.

What you mentioned about an event inside the actor

  • in the actor who owns the component:

  • in the widget:

getting squished

The red bit above will fill the space evenly assuming the below is the horizontal box:


This can be further improved, most likely. Depending on why we must do this, and what we need to achieve:

Perhaps it’s the actor that should create the widget? Or does it already own the widget component? Is this how it’s supposed to work?

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!

1 Like

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:


Collision to hit ray so it triggers the BP, that calls the widget:

1 Like

Ah, makes sense. Carry on then!

1 Like

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. :person_shrugging: 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.

https://www.youtube.com/watch?v=v9k-J2GeEKI

There’s some good dos and don’ts here, too:

https://dev.epicgames.com/community/learning/knowledge-base/VZZD/unreal-engine-slate-general-optimization-guidelines

Thank you! Very helpfull!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.