Download

How to get Image component of the blueprint?

I have a dialog widget and depending of situation I need to be able to set special image icon in it. How can I get image component using c++?

.h

  1. UPROPERTY(EditAnywhere) TSubclassOf<UUserWidget> widgetDialogBottom;
  2. UUserWidget* widgetDialogBottomInstance;

.cpp

  1. widgetDialogBottomInstance = CreateWidget<UUserWidget>(GetWorld(), widgetDialogBottom);
  2. widgetDialogBottomInstance->Image(“mi_dialog_2”); // I need something like this
  3. widgetDialogBottomInstance->AddToViewport();


So what’s the situation when you need to set a special image icon? Depending on your answer, you could probably do it in blueprint, or have a BlueprintImplementable function in C++ that you could implement in blueprint and call from c++

I need to write a name of image (it is material instance actually) in code and see the result in dialog screen. How can I do this BlueprintImplementable function in c++. Can you show me the code? Because I am new in UE

Here is an example of BlueprintImplementableEvent:

You declare the function in your .h file:


UFUNCTION(BlueprintImplementableEvent)
void YourFunctionName(int32 whateverParameters); 

You can call this function anywhere in C++, but it will actually be implemented in Blueprint (so, you need to go to the child class in Blueprint and implement that function). That could be one way of accessing variables from blueprint but calling the function itself from C++.

I’m not sure if that’s what you need because I haven’t seen your code structure, but this is one way of doing things. Let me know if anything is unclear

I highly recommend doing a C++ UE4 tutorial before attempting your own game, it will teach you the basic concepts. The Battery Collector one is pretty good, and it only took me like a week to go through: https://www.youtube.com/watch?v=mSRov77hNR4&list=PLZlv_N0_O1gYup-gvJtMsgJqnEB_dGiM4