Changing texture on Image widget at runtime and keeping aspect ratio correct?

I have a problem with getting dynamically changed image appear with correct aspect ratio using ScaleBox (or not using ScaleBox, either way I can’t get it right). I’m making an inventory system where I dynamically load and switch item images when items are loaded. The loading is currently done in construct because I’m trying to get the image aspect ratio work properly, but basically it gets a row from item data table, and assigns a texture called as ItemArt to the widget that is drawn on screen, however, ScaleBox only seems to update when you manually change an image in Image instead of when it’s changed via blueprint.


In above image you can see how I’ve set up the Hierarchy for the widget. The ItemCanvas is basically sized based on size of children. The ScaleBox is set to “Scale To Fix” and direction is both. The ItemArt is made to fit ScaleBox slot. This works fine if I change the image in the ItemArt manually, problems come when it’s changed dynamically via Blueprints.

In the above image you can see the Graph for the item. It’s currently set to pre construct for testing, but I can set it to any other vent type too, and it behaves the same (and that behavior is not correct as art aspect ratio is not respected). First it grabs the ItemData row from a DataTable called as Items, and then it takes the ItemArt texture from there and assigns it to ItemArt Image on the widget.

This is basically where the issue comes; The ScaleBox does not update the Image size(s) as the Image is switched via Blueprint. Again, switching manually respects the aspect ratio of the image, but setting it via Blueprint doesn’t.

The last bit just rotates the image based on what I’ve set as the display rotation which works and cutting the connection won’t do anything to fix the aspect ratio :slight_smile:

In this last image you can see me adding this item widgets to Inventory widget and I’ve changed their default ItemData types; Some of them are axes, some knives, and some swords, but they’re all basically square as they match the default image set in ItemArt in the widget itself (the “Missing Item” art I’ve set as base art to know if there’s issues or missing data).

I originally tried to get texture size information and use that, but I couldn’t find a way to do that, and then I switch to trying to do it via ScaleBox, but my success has been really low on that end. I tried finding if there’s a way to force the ScaleBox to update via Blueprint, but I couldn’t find if such option exists.

Any idea what I’m doing wrong, or what I should be doing better to get it work?

Thank you!

Currently handling this by calculating image aspect ratio in photoshop and then manually inputting it in item information along with width I want it to appear in game. Not optimal, but as there doesn’t seem to be any other solutions to it I have to go manually :o

(Won’t mark this as an answer, because it isn’t particularly an answer and the issue remains)