How to set or change a UMG texture, based on a Boolean Array?

Hello everyone!

I’m trying to figure out how to change a button’s texture in UMG, based on a Boolean array.

This is for the level select screen of my game, the “unlocked” levels are stored in a Boolean array. True = Unlocked.

I would like a different texture to display on the “Locked” or False levels. To give feedback that they’re still locked.

How would I go about doing this? Any help is appreciated!

see my video man Tutorial Unreal Engine 4 UMG Set Material. - YouTube

Alright, I spent some time on this one as it seemed like a fun morning brainhunt and it’s directly useful for many other projects.
I’ve included in the example an implementation of loading from a save file as well since that seems like an important thing to do in this case. If you have further questions feel free to ask!

So! time to explain :smiley:

I wanted to start with a struct to keep everything level-oriented grouped together nicely. So create a struct in your content browser that contains the following:

  • Level unlocked image array
  • Level locked image array
  • Is Level Unlocked Boolean array

Populate the arrays with your desired content and default values as shown in my example here:

http://i.imgur.com/bjwJDS5.png

Next, on construct we need create an array of all the level buttons or images and save that off as a variable ‘level button array’ for the next few steps. Then we need to make sure we set all the images to their correct ‘islevelunlocked?’ state for each index of the ‘level button array’.

I added the optional branch “does save file exist” in order to give you a chance to load save data to the struct before the initial foreach reads from the struct on construct.

http://i.imgur.com/0NHMv4m.png

Next I made an example of how you would unlock the next level. To do that we need to scan for the next locked level and return the index of that in order to unlock it and set its widget style to unlocked. Optionally, and not shown, you can save off the last unlocked level as a variable and use index +1 instead of a foreach whenever you unlock a level. This would be useful if you had a large amount of levels.

http://i.imgur.com/eA2TEII.png