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:
http://www.zduhach.se/blog/Images/Unit_generation2.png
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:
http://www.zduhach.se/blog/Images/Widget_binding.png
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.
http://www.zduhach.se/blog/Images/result04.png
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?