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++?
UPROPERTY(EditAnywhere) TSubclassOf<UUserWidget> widgetDialogBottom;
widgetDialogBottomInstance = CreateWidget<UUserWidget>((), widgetDialogBottom);
widgetDialogBottomInstance->Image("mi_dialog_2"); // I need something like this
One way of doing it finding a widget:
But since you trying to establish some C++ interface that you control UMG widget from C++ there better way. Widget Bluepritns are normal blurpints so they are classes based out of other class, in case of Widget Blueprints UUserWidget… and yes since they are blueprints you can make base class for it in C++, just make UUserWidget class in C++ and reparent your widget blueprint to that class or you can use blueprint creation menu (one when you create normal Blueprint) and pick you UUserWidget class, UE4 editor will detect it’s a widget class and automatically will make Widget Blueprint instead.
This have a lot of benefits, as you will be able to communicate with widget same way as you do with actors. You can make series of BlueprintImplementableEvents and variables that will let you trigger things in widget from C++
I’m not sure that I understand. Should I do something like this? And how can I set up specific Image?
UCLASS() // Class, from where I want to change image component
class HOME_API AAct_31 : public AActor
class UDialogWidget : public UUserWidget
void SetImage(UTexture2D* InTexture);
UPROPERTY(meta = (BindWidget)) UImage* CharacterPreview;
void UDialogWidget::SetImage(UTexture2D* InTexture)
I think you’re on the right track. In blueprints I think to set the Image you have to Set the whole slate brush struct at a time, including the Image reference.