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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Rendering a UMG Widget on a Static Mesh?

So, im working on a 3d " journal " interface, where the UI is drawn on a plane inside the journal model. I exposed the material instance on the UMGWidgetComponent so i can grab it and apply it to my mesh instead...My problem is that while i can apply the material just fine i cant get it to make the ui Somehow " fit " inside the plane, i also tried with a few different meshes with mixed results

Left is the UMG Widget material applied to a mesh, Right is the normal result on a widget component

Applying the Material to a plane, gives fairly good results ( although with some stretching , it " stretches " the UI based on the plane scale , ideally id like the UI to not be stretched )

alt text

Using a scaled down cube works well too

alt text

And here is where the problem is. When using my own journal model . the pages have their own material slot and they are just planes.. the problem is that the UI doesnt fit at all inside these

alt text

alt text

So yeah basically im trying to find a way to make the material / UI "fit" on the specific UV / Material region

Product Version: UE 4.10
more ▼

asked Dec 31 '15 at 01:11 PM in Rendering

avatar image

95 15 17 23

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

This is how I render the UMG into a texture.

 * Renders a UMG Widget to a texture with the specified size.
 * @param Widget        The widget to be rendered.
 * @param DrawSize    The size to render the Widget to. Also will be the texture size.
 * @return            The texture containing the rendered widget.
 UTexture2D* UTextureUtilsBPLibrary::TextureFromWidget(UUserWidget *const Widget, const FVector2D &DrawSize)
     if (FSlateApplication::IsInitialized()
         && Widget != NULL && Widget->IsValidLowLevel()
         && DrawSize.X >= 1 && DrawSize.Y >= 1)
         TSharedPtr<SWidget> SlateWidget(Widget->TakeWidget());
         if (!SlateWidget.IsValid()) return NULL;
         TSharedPtr<FWidgetRenderer> WidgetRenderer = MakeShareable(new FWidgetRenderer(true));
         if (!WidgetRenderer.IsValid()) return NULL;
         UTextureRenderTarget2D *TextureRenderTarget = WidgetRenderer->DrawWidget(SlateWidget.ToSharedRef(), DrawSize);
         // Creates Texture2D to store RenderTexture content
         UTexture2D *Texture = UTexture2D::CreateTransient(DrawSize.X, DrawSize.Y, PF_B8G8R8A8);
         Texture->MipGenSettings = TMGS_NoMipmaps;
         // Lock and copies the data between the textures
         TArray<FColor> SurfData;
         FRenderTarget *RenderTarget = TextureRenderTarget->GameThread_GetRenderTargetResource();
         void* TextureData = Texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
         const int32 TextureDataSize = SurfData.Num() * 4;
         FMemory::Memcpy(TextureData, SurfData.GetData(), TextureDataSize);
         // Free resources
         return Texture;
     return NULL;

This will always create a new UTexture2D. You can alter it for your needs and to use always the same texture, for performance.

more ▼

answered Aug 30 '16 at 08:33 PM

avatar image

1.1k 28 39 90

avatar image alvarofer0020 Aug 30 '16 at 08:47 PM

HUGE Thanks!, thats exactly what i needed

avatar image RVillani Aug 30 '16 at 08:54 PM

You're welcome, man! But wasn't your problem related to the mapping? I thought you had sorted out the "render UMG on any object" problem. XD

avatar image Freelancer95 Mar 05 '18 at 03:27 AM

Please add includes, I have no idea where you got "MakeSharable", "WidgetRenderer" or "FWidgetRenderer" from.

avatar image JaroMast Jun 18 '18 at 11:15 AM
 #include "SharedPointer.h"
 #include "WidgetRenderer.h"
avatar image Maciej Fwh 4 days ago

How to use this function? Where can I/should I call it?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

How did you expose the material instance? That's really interesting!

For the UI in the page, I see some options:

  • Remap your pages UVs so that the page fills the UV completely, as the UI texture seems to do. Probably the most practical way of solving your problem.

  • See if the texture from the UI is passed to the material instance as a parameter. If it is, you could get that parameter and use it on a custom material of yours, with your own texture coordinates.

  • Just place the widget right in front of the page, really close, so it seems it's in the page (this is the silly one XD)

more ▼

answered May 10 '16 at 09:55 PM

avatar image

1.1k 28 39 90

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

hi,could you show me the way to Render a umg widget on a static mesh.I am a newer,could you show me the code?

more ▼

answered Aug 30 '16 at 11:51 AM

avatar image

1 2 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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