Render Widget to Render Texture 2D with alpha

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)

255354-capture2.png

And finally, this is the material I use (you can see on the left what’s the result)

Any thoughts?

Did you ever figure this out?

Just set the background of the widget to be a color that’s not in use and then mask that same color in the material editor.

Try Set ClearColor’s Alpha to 0 in RenderTarget

1 Like

thank you

What did the header (.h) end up looking like for this?