What class to use for UMG Image

I have a UMG HUD that display Images (icons that are dynamic for player abilities available at the time). I have a struct that I use to build a TArray in C++ holding the current abilities. It works fine except that the settings on the pawn blueprint which include the image setting, will not “Cast to Image” in UMG. I’m using UObject* right now (also tried FTexture, FTexture2D and converting to a brush on the UMG side), because I was trying to avoid adding UMG includes into my basic project h file so I could specify UImage* for the image. Here is the struct.

USTRUCT(BlueprintType, Category="Special Abilities")
struct FSpecialAbilities {
    /** Display Description for Special Ability **/
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Special Abilities")
    FString Description;
    /** Time Special Ability will last **/
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Special Abilities")
    float RunTimer;
    /** Time Special Ability will not be available after use **/
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Special Abilities")
    float CooldownTimer;
    /** Error message to use while this ability is active **/
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Special Abilities")
    FString ErrorMessage;
    /** Determines if this is timed or a toggle **/
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Special Abilities")
    bool IsTimed=true;
    /** Screen Image for UMG **/
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Special Abilities")
    UObject* ScreenImageForUMG;

Then in various types of pawns, it creates a TArray as follows, and those are looked at by the UMG HUD for that Pawn type.

/** Array of Special Abilities for Flight Vehicle **/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Special Abilities")
TArray<FSpecialAbilities> SpecialAbility;

The “ScreenImageForUMG” is supposed to be what is passed to UMG to allow it to display this image. The Cast to Image fails and it doesn’t display it in the Image widget. I had thought UObject would be sufficient since UImage inherits from UObject.

The picture shows the UMG Blueprint code I’m using to try and get the Image into the UMG widget. The “Ability Slot 1” is where the image should go and is defined as an “Image” widget in the Designer. What class should I be using for this variable? Is this completely the wrong approach to getting an image set in the UMG widget from C++?

Not sure if this is the answer you are looking for, but I hold my references to icons as TAssetPtr<UTexture2D> then I get pointer to the asset object of type UTexture2D by calling LoadSynchronous() on the TAssetPtr.
Once I get the asset object I setup UImage brush(FSlateBrush).

TAssetPtr<UTexture2D> icon;
FSlateBrush imageBrush{};
imageBrush.ImageSize = FVector2D{the size};

UImage *image = NewObject<UImage>(); // im creating the image widget in code as well

You can probably use “Set brush fromt texture” node in blueprints to setup image with icon

Thanks Very much. I’ll try this and get back to you.

I wasn’t able to get the FSlateBrush to work under XCode, linker errors stopped me from testing your solution. I certainly appreciate the response and wish that I could test it. I’m still beating my head against the wall getting the the image object in UMB blueprint to accept anything. I am not even able to create an array as a UMG Image Object Reference variable and set the image from it. The only way I can get an image into it, is to do it within the designer, which makes it uselessly static. I know others are dynamically changing images in UMG, but I’m sure not getting it.

This did provide the solution, not directly from your code, but applying your code’s concept to my application. The class needed to be UTexture2D as yours is, then I did use Set Brush from Texture as you said, using my image widget as an input. Worked fine that way. I’d tried this before I asked the question, but didn’t realize that in my test, I didn’t reset the variable with a value after the compilation, a dumb error that cost me a day. Your solution contributed to my figuring it out and I’m going to call it solved.