1
\$\begingroup\$

I have a custom widget with an image component. I want to change the image dynamically based on a string from a data table. How do I do this?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Where is the iamge located? Is it on the web, the computer's filesystem, a uasset inside your project or something else? \$\endgroup\$
    – Sturlen
    Oct 29, 2017 at 10:03
  • \$\begingroup\$ It is an image asset that is already registered in Unreal (already is a uasset). \$\endgroup\$ Oct 29, 2017 at 23:12

1 Answer 1

1
\$\begingroup\$

C++
You can use the LoadObject function to find and load and object at runtime. Full documentation is available from Epic Games here. For loading an image the following should work:

GridTexture = LoadObject<UTexture2D>(NULL, TEXT("/Engine/EngineMaterials/DefaultWhiteGrid.DefaultWhiteGrid"), NULL, LOAD_None, NULL);

Blueprint
As of yet there is no native implementation, but it is included in Rama's Victory Plugin.

The Load object from asset path node

Select the class you want to want to load and give it the reference path of your asset. The loaded asset will be an Object so you will have to cast it to Texture2D. Then you can store it as a variable or directly set the image of your widget.
Below is an example of using this with a DataTable with some assets.

full example with datatable

To get a usable reference, simply right click an asset and select Copy Reference.

\$\endgroup\$
1
  • \$\begingroup\$ I tested this, and it definitely worked. Thanks again. Note: To get the "reference path", right-click on the asset in the asset viewer and select "Copy reference". \$\endgroup\$ Nov 1, 2017 at 4:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .