Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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!

Product Version: UE 4.10
more ▼

asked Feb 19 '16 at 03:18 PM in Blueprint Scripting

avatar image

46 18 25 28

avatar image rjvm Feb 19 '16 at 09:21 PM
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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 :D

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:

alt text

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.

alt text

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.

alt text

more ▼

answered Feb 20 '16 at 04:44 PM

avatar image

276 22 20 26

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question