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 {
GENERATED_USTRUCT_BODY();
public:
/** 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++?