x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Is there a way to Render UMG to a texture

Hi, I want to know if it is possible,if yes how, to Render a UMG Widget to a texture and apply it to a mesh. I want to make a SAO style Healthbar that the opponent will see.

Product Version: UE 4.10
Tags:
more ▼

asked Mar 30 '16 at 02:14 PM in Using UE4

avatar image

FirePhoenixOffical
6 1 2 5

(comments are locked)
10|2000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered Feb 26 '19 at 12:25 PM

avatar image

lewisscrivs
26 1 2 5

avatar image LX.Simedix Apr 10 '19 at 10:03 AM

thanks u very much , very nice

(comments are locked)
10|2000 characters needed characters left

You could use the (experimental) 3D Widget Component instead of a Texture. You wont be able to wrap it around the whole model, but if you only want a UI rendered on a flat surface it works just fine.

Here is a tutorial about this: https://docs.unrealengine.com/latest/INT/Engine/UMG/HowTo/Create3DWidgets/

more ▼

answered Jul 05 '16 at 03:24 PM

avatar image

fabianu
498 12 9 34

(comments are locked)
10|2000 characters needed characters left

The only way I have figured out how to do it is to set up a SceneCaptureComponent2D to capture a 3D Widget Component and render it to a render target. However, this will not allow the same level of control over the transparency.

I would recommend checking out this if you know anything about programming in C++

more ▼

answered Mar 05 '18 at 01:39 AM

avatar image

Freelancer95
1 1 2 2

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question