This draws a line and a material to a UCanvasRenderTarget2D from the delegate triggered by UpdateResource(). The material draws to the screen fine from blueprint but drawing to the texture doesn’t appear to work. As the Line and Material are sharing a set of coordinates you should expect to see a Crosshair where the line and bullets are intersecting. However the Material is clearly not there.
The Material tile appears to be added to the Renderbatch correctly so I’m not sure what’s going on.
void UWavesUIElement_MousePointer::DrawElement(UCanvas* C)
{
if (IsUsingGamepad())
return;
FVector2D ScaledSize = GetScaledSize(GetHUD()->ScreenScale.X);
FVector2D MousePosition;
GetHUD()->GetMouseCoordinates(MousePosition);
Position = MousePosition;
switch (Alignment)
{
case EUIAlignment::UIALIGN_Center:
Position.X -= ScaledSize.X / 2;
Position.Y -= ScaledSize.Y / 2;
break;
case EUIAlignment::UIALIGN_Right:
Position.X -= ScaledSize.X;
Position.Y -= ScaledSize.Y;
break;
}
if (!PointerMID)
{
PointerMID = UMaterialInstanceDynamic::Create(PointerMaterial, this);
PointerMID->SetVectorParameterValue(FName("Color"), PointerColor);
}
if (PointerMID)
{
FVector2D CoordinatePosition(0, 0);
FVector2D CoordinateSize(128, 128);
C->K2_DrawMaterial(PointerMID, Position, ScaledSize, CoordinatePosition, CoordinateSize);
C->K2_DrawLine(Position, CoordinateSize, 10.f);
}
}