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"

Can't seem to get a texture from an array?

Hi, So I'm trying to change the image brush in my UI widget dynamically, grabbing the image (Texture 2D) from the struct of a randomly generated unit in my game. The image is supposed to be a character portrait that gets assigned randomly when the unit is generated. This is what the unit generation function looks like: alt text It's built in a function library and the array of portraits is a local variable I manually populated with images. The idea is to grab a random image from the "Portrait" array and set it as the "Character Portrait" variable in the struct.

In my widget I've created an image object and a binding to change the appearance. This is what the binding looks like: alt text

So basically it loads a default image file as long as no item (in a list of units) is selected, once an item is selected it should load the image from the struct of the selected unit. alt text Left is what the widget looks like loading the default image set in the binding, right is the result of selecting an item in the list and getting the image stored in the unit struct. I've fiddled around with it and tried to change the image in the widget using different methods but that doesn't change anything. From what I can tell the problem lies in the unit generation and changing the image variable of the unit struct. Hiding the pin and not changing the image that is set as the default of "Character Portrait" changes the image fine in the widget, but I can't figure it what I'm doing wrong when setting the variable to a random array element in the struct?

Product Version: UE 4.10
more ▼

asked Dec 07 '15 at 07:56 PM in Blueprint Scripting

avatar image

11 2 3 5

avatar image Zduhach Dec 07 '15 at 09:37 PM

Okay small update, I've narrowed the problem down to the Character Portraits array not returning anything on Get.

I hooked up a button that runs my unit generation function with two new outputs, one gets index 0 in the Character Portraits array, and the other gets index 0 in an array of strings. I just hooked both the outputs up to a print string function. The result can be seen on the right, one empty line and the string from index 0 alt text Is this a bug or are you not allowed to store Texture2D in an array?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Okay, so a work around that works is to change the struct variable to a "slate brush" and set that from an array of slate brushes instead. Only problem here is that I have to set the "max" value of the "random int in range" node manually, hooking up the length of the array will have every nth Get store a void value and the white box from the first post appears again.

more ▼

answered Dec 07 '15 at 09:53 PM

avatar image

11 2 3 5

avatar image CometGoat May 04 '18 at 01:09 PM

Brilliant, thank you so much. I was experiencing this problem in a game jam with only 3 hours left, and this really saved my hide. It was a card game without any cards until I tried your fix.


avatar image Zduhach May 05 '18 at 11:28 PM

Cheers m8, glad you made it on time!

(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