0
\$\begingroup\$

I have a dialog screenwith character icon and I need to be able to set up this image in code. But I don't know how to access this Image component (I put material instances in it).

.h

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

.cpp

widgetDialogBottomInstance = CreateWidget<UUserWidget>(GetWorld(), widgetDialogBottom);
widgetDialogBottomInstance->Image("mi_dialog_2"); // Need something like this
widgetDialogBottomInstance->AddToViewport();

enter image description here

enter image description here

I made a class DialogBottomWidget:

.h

UCLASS()
class HOME_API UDialogBottomWidget : public UUserWidget 
{ 
        GENERATED_BODY()

    public: 
        void SetImage(UTexture2D* InTexture);

    private: 
        UPROPERTY(meta = (BindWidget)) UImage* CharacterPreview;
};

.cpp

#include "DialogBottomWidget.h"

void UDialogBottomWidget::SetImage(UTexture2D* InTexture)
{
    CharacterPreview->SetBrushFromTexture(InTexture);
}

.. and then I made a blueprint based on that class. What should I do now?

I can get reference to image MaterialInstanceConstant'/Game/Materials/Faces/mi_dialog_2.mi_dialog_2', but how to put it to image component of the blueprint?

enter image description here

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

The variable widgetDialogBottomInstance should be of type UDialogBottomWidget rather than the generic UUserWidget. By having the proper type for both the variable and the CreateWidget function template parameter, you'll be able access the SetImage function you wrote:

UDialogBottomWidget* widgetDialogBottomInstance;
... 
widgetDialogBottomInstance = CreateWidget<UDialogBottomWidget>(GetWorld(), widgetDialogBottom);
widgetDialogBottomInstance->SetImage(...); // You can call SetImage here

Cheers!

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .