Hey there!
I’m displaying a User Widget in my HUD class (using AddToViewPort()).
Problem is that one of the widgets disappears when drawing in some ways to the canvas. This only happens in the standalone game. In the editor PIE it all works.
Here’s my DrawHUD function:
void AMyHUD::DrawHUD()
{
Super::DrawHUD();
this->Canvas->SetDrawColor(255, 255, 255, 255);
if (this->UserWidget1)
DrawUserWidget1(); // simply updates elements in the user widget
// Drawing a line always works and doesn't interrupt User Widgets
FCanvasLineItem Line(
FVector2D(0.0f, 0.f), FVector2D(Canvas->SizeX, Canvas->SizeY)
);
Line.BlendMode = ESimpleElementBlendMode::SE_BLEND_Translucent;
Canvas->DrawItem(Line);
// This seems to interrupt UserWidget2. It’s not displayed any more when this line runs.
// NOTE: If DrawMaterialTriangle (the one below) is run after DrawMaterialSimple(…) (this line) BOTH user widgets show!!!
DrawMaterialSimple(this->MyMaterialInstanceDynamic, 0,0,300,300);
// Though this doesn't seem to be an option for this project, I tested this and it doesn't interrupt user widgets. They both show fine.
DrawMaterialTriangle(this->MyMaterialInstanceDynamic,
FVector2D(0.0f,0.0f),
FVector2D(100.0f, 0.0f),
FVector2D(100.0f,100.0f),
FVector2D(0.0f,0.0f),
FVector2D(100.0f, 0.0f),
FVector2D(100.0f,100.0f)
);
// With this one, only UserWidget1 displays. UserWidget2 doesn’t display. Even when putting UserWidget2 drawing before UserWidget1 drawing, it won’t display. Putting UserWidget1 at the end of the function results in the same: UW1 is drawn, UW2 is not drawn. Obviously, this then has something to do with the setups of the user widgets (see below).
// I also tried to move the tile to other positions since UserWidget2 is situated in the center. But moving still has the same results.
// This seems to be the same as DrawMaterialSimple(…)
FCanvasTileItem Tile(
FVector2D(Canvas->SizeX/2, Canvas->SizeY/2),
this->Chargebar->Chargebar->GetRenderProxy(false),
FVector2D(Canvas->SizeX*0.2, Canvas->SizeY*0.2)
);
Canvas->DrawItem(Tile);
// Drawing a simple tile without a material does NOT interrupt the user widgets.
FCanvasTileItem Tile2(FVector2D(Canvas->SizeX/2, Canvas->SizeY/2), FVector2D(Canvas->SizeX*0.2, Canvas->SizeY*0.2), FLinearColor(1.f, 0,0));
Canvas->DrawItem(Tile);
if (this->UserWidget2)
DrawUserWidget2(); // also just updates widget elements
}
Here is an excerpt of my User Widget hierarchy:
MyHUDUserWidget
[Canvas Panel]
[Scale Box]
UserWidget1 (Overlay) // uses Images with materials
[Scale Box]
BackWidget (Overlay) // this is used to just set a UImage with a material as a background. This is also affected by the bug equally as UserWidget2
UserWidget2 (Overlay) // uses Images with materials
I just found another “fix”. Adding a simple Border widget to BackWidget (see above) “fixes” it.
Where as:
MyHUDUserWidget
[Canvas Panel]
[Scale Box]
UserWidget1 (Overlay)
[Scale Box]
BackWidget (Overlay)
UserWidget2 (Overlay)
[Border]
results in only the BackWidget showing.
And
MyHUDUserWidget
[Canvas Panel]
[Scale Box]
UserWidget1 (Overlay)
[Scale Box]
BackWidget (Overlay)
[Border]
UserWidget2 (Overlay)
results in both BackWidget and UserWidget2 showing. So it seems to matter if Border is first or second child of BackWidget.
The core message is probably then:
Why does drawing a tile to canvas with a dynamic material instance interrupt UserWidget2?
Why does DrawMaterialTriangle(…) “fix” this?
Why does adding a Border to UserWidget2 “fix” this?