Hi again!
I was able to make a c++ class that renders a widget to a render target texture by using WidgetRenderer->DrawWidget method. However, the issue is that the final result of rendering doesn’t include transparency, and that transparency was the whole point of what I was trying to do… Here’s the code:
void APlayerPawnBase::RenderWidgetToTexture(UUserWidget *const Widget, FVector2D const &DrawSize, float DeltaTime)
{
if (!IsValid(widgetRenderTargetTexture))
{
return;
}
if (!IsValid(Widget))
{
return;
}
if (DrawSize == FVector2D(0, 0))
{
return;
}
TSharedRef<SWidget> ref = Widget->TakeWidget();
WidgetRenderer->DrawWidget(widgetRenderTargetTexture, ref, DrawSize, DeltaTime);
}
I tried clearing render texture before rendering widgets with a clear color, and as long as I don’t draw widget over it it has alpha, but after rendering widget, alpha goes away.
This is my RT setup:
This is how I render the widget in BP:
This is my widget in editor (just to show you guys that there should be transparency)
And finally, this is the material I use (you can see on the left what’s the result)
Any thoughts?