How to change texture on HUD based on mouse click event?

Hi there guys! :slight_smile:

I’m making an idle game like this:

How can I change the texture of the “stuff you mine” (in the example above: poo/paper/salt/etc) based on the click of the button to the left/right? I have a “Level counter” which adds one to a variable by the click on the right arrow, and subtract one if i click on the left arrow. It makes sense to me that I rename the textures to “1”, “2”, “3”, etc and draw texture “1” when the “Level counter” is on 1, draw texture “2” when the “Level counter” is on 2, etc.

The only question is how can I do that? I found this good solution, but using a branch for every selection sounds a bit over complicating things:

I know there is a simpler solution, just can’t find it. Any suggestions are welcome!

Thank you! :slight_smile:

Create a custom Enum in the content browser.
Then use a Switch on Enum to change the variable for the Material or Texture just before the DrawMaterials in HUD.

NB: When you promote the variable off the selection pin on the Switch on Enum, it will be a Byte type.
Change this by deleting it off the graph, going to the new variable in MyBlueprints and changing it to the type you’ve created, ie TextureSwapperEnum. Drag it back onto the graph into the Selection pin. This will then display your choices and not just numbered choices.

Tom

Hi Tom, thanks for the quick answer.

If I use Switch on Enum it gives me an exec option to each list item. What I’m looking for is rather an automated version of this, so I do not wish to manually set every texture, but to process a data and automatically select the texture needed, something like this:

1 - get a variable, like the level of the stuff the player can “mine” in the game
2 - feed the variable to ??? (this is where I get stuck)
3 - based on the variable ??? selects a texture
4 - Draw texture based on the selected variable

So basically I need an output that I can feed to the Texture selection in the Draw Texture node

I dunno what you’re finally after, but this is what I was on about.

15715-2014-09-18+22_14_05-.png

I see now.

Your solution works, my only problem is I have got like 200+ textures in the game. It would be a massive pain to set up every one of them this way. Like I said, I’m looking for an “automated” solution, where I can draw the texture based on a variable, be it a number or the name of the texture, I dont really mind. Wiring 200+ textures manually sounds too complicated, Im sure there is a simpler solution.

If there are many, you’ll have to pull them out of an array by index then I guess,