Get Image from Widget Blueprint in C++

Hey,

I’m new to Unreal Engine and currently practicing to code with it in C++.

I made a Widget with an image in its canvas.

How can I access this image from my C++ code ?

I made a new UserWidget class and reparented it.

My current attempt was something like that:

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "A Props")
		TSubclassOf<class UImage> wImage;

After this step I wanted to call a Tick void in my Widget class and fade my image in and out like I did in blueprint before. My code is currently like that:

Header:

UCLASS()
class VEHICLEEXAMPLE_API UMyUserWidget : public UUserWidget
{
	GENERATED_BODY()
	
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "My New User Widget")
		FString MyNewWidgetName;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "A Props")
		TSubclassOf<class UImage> wImage;

	virtual void BeginPlay();

	void Tick(FGeometry MyGeometry, float InDeltaTime);

	float timer;

	bool b_;
	
};


 
    
    CPP:
    
    #include "VehicleExample.h"
    #include "MyUserWidget.h"
    
    void UMyUserWidget::BeginPlay()
    {
    
    }
    
    void UMyUserWidget::Tick(FGeometry MyGeometry, float InDeltaTime)
    {
    
    }

Thanks :slight_smile:

Hi Memorix101

I suggest you add a BlueprintImplementableEvent to UMyUserWidget like so:

UFUNCTION(BlueprintImplementableEvent, Category = "My User Widget")
UImage* GetMyImage() const;

Then, you go into your Widget-Blueprint and override the function. Inside the function’s implementation you return the image.

Now, within your C++ code you can simply call GetMyImage() and you will receive the pointer to the UImage, as returned from the Blueprint implementation.

Cheers,
Elewyth