Is there a way to Render UMG to a texture

Yeah but you’ll need to create a C++ class to access the needed functions…

Dependances in Build.cs file:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" , "UMG", "Slate", "SlateCore", "RenderCore"});

PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore", "RenderCore" });

H File:

/**
* Renders a widget to a Render Texture 2D with the given draw size.
*
* @param widget      The widget to converted to a Render Texture 2D.
* @param drawSize    The size to render the Widget to. Also will be the texture size.
* @return            The texture render target 2D containing the rendered widget.
*/
UFUNCTION(BlueprintCallable, Category = RenderTexture)
class UTextureRenderTarget2D* WidgetToTexture(class UUserWidget*const widget, const FVector2D &drawSize);

/* UPROPERTY initialized so UE4 will handle its garbage collection correctly... */
UPROPERTY(BlueprintReadWrite, Category = RenderTexture)
class UTextureRenderTarget2D* TextureRenderTarget;

CPP File:

UTextureRenderTarget2D* UComputerWidget::WidgetToTexture(UUserWidget *const widget, const FVector2D &drawSize)
{
	// As long as the slate application is initialized and the widget passed in is not null continue...
	if (FSlateApplication::IsInitialized() && widget != nullptr)
	{
		// Get the slate widget as a smart pointer. Return if null.
		TSharedPtr<SWidget> SlateWidget(widget->TakeWidget());
		if (!SlateWidget) return nullptr;
		// Create a new widget renderer to render the widget to a texture render target 2D.
		FWidgetRenderer* WidgetRenderer = new FWidgetRenderer(true);
		if (!WidgetRenderer) return nullptr;
		// Update/Create the render target 2D.
		TextureRenderTarget = WidgetRenderer->DrawWidget(SlateWidget.ToSharedRef(), drawSize);
		// Return the updated render target 2D.
		return TextureRenderTarget;
	}
	else return nullptr;
}

After all of this has been implemented your going to have to cast the UTextureRenderTarget2D into a UTexture so it can be passed as a texture parameter to the material instance (Only in C++), although you could just add this at the end of the function and just have it return the UTexture to make things easier.

4 Likes