I am interested in my UI purely using Slate (no UMG).
I am struggling to figure out how to update an SImage in my widget to use a material.
My updateImage function seems to be working because in game I can see the transparent red:
but when I comment out the "test.SetColorAndOpacity(menuBackgroundRed);"code and then use my “test.SetImage(testController->itemMat);” line I don’t see anything
I have the material domain set to User Interface, not sure what I’m missing. The material for now is just black with green lines across it.
//ATestPlayerController.h
class MYPROJECT_API ATestPlayerController : public APlayerController
{
GENERATED_BODY()
public:
UMaterial* itemMat;
...
//ATestPlayerController.cpp
ATestPlayerController::ATestPlayerController()
{
static ConstructorHelpers::FObjectFinder<UMaterial>itemMaterialAsset(TEXT("Material'/Game/itemIconMaterial'"));
itemMat = materialAsset.Object;
}
//SItemWidget.h
class MYPROJECT_API SItemWidget : public SCompoundWidget
{
public:
SLATE_BEGIN_ARGS(SItemWidget){}
SLATE_ARGUMENT(TWeakObjectPtr<class ATestHud>, OwningHUD)
SLATE_END_ARGS()
void Construct(const FArguments& InArgs);
SOverlay::FOverlaySlot* slotOverlayItemImage;
...
//SItemWidget.cpp
void SItemWidget::Construct(const FArguments& InArgs){
FColor menuBackground{0, 0, 0, 80};
ChildSlot
.HAlign(HAlign_Left)
[
SNew(SCanvas)
+SCanvas::Slot()
.Position(FVector2D(20, 500))
.Size(FVector2D(400, 400))
.HAlign(HAlign_Left)
.VAlign(VAlign_Center)
[
SNew(SOverlay)
+ SOverlay::Slot()
.HAlign(HAlign_Fill)
.VAlign(VAlign_Fill)
.Expose(slotOverlayItemImage)
[
SNew(SImage).ColorAndOpacity(menuBackground)
]
...
void SItemWidget::updateImage(){
FLinearColor menuBackgroundRed{255, 0, 0, 80};
ATestPlayerController* testController = Cast<ATestPlayerController>(OwningHUD->GetWorld()->GetFirstPlayerController());
SImage& test = static_cast<SImage&>(slotOverlayItemImage->GetWidget().Get());
test.SetImage(testController->itemMat);
//test.SetColorAndOpacity(menuBackgroundRed);
}