x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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. alt text

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 :)

Product Version: UE 4.8
Tags:
myimageue4.png (198.2 kB)
more ▼

asked Aug 19 '15 at 05:21 PM in C++ Programming

avatar image

Memorix101
3 1 1 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

more ▼

answered Aug 20 '15 at 11:23 AM

avatar image

Elewyth
412 24 19 34

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question