UMG as Mateiral?

How would one go about using a UMG widget as material that can be applied on a mesh surface?

For example if I want the menu list to be displayed on a page of a book (looks fancy) it should follow the curve of the page etc, so what would be the proper way to do this or is it possible using default engine features?

Heh, what you’re wanting is not 100% possible in engine at the moment. You can fake it though. Or you could try 3D widgets. 3D Widget Docs

The only other thing I can think of, is actually modeling the book/page and then texture it accordingly to how the player would see it, but fake it to “curve” around the page, so you still have it as a UMG button.

to get UMG on a texture applied to a mesh, you would have to spawn an actor with a 3D widget component, and render it with a SceneCaptureComponent, which will update a texture you can use in a material applied to your book.

i think it would be more efficient if 3D widgets allowed you to replace their plane mesh, but currently, you would need to add that functionality with c++.

ayy ! that’s a good point , I think Changing the render target for umg itself is a better way, but it’ll mess up the mouse input in some cases due to the curvature. gonna give this a try.

Got proof of concept working without extra render targets by extending UWidgetComponenet :slight_smile:

wow, could you explain how you did it? i haven’t actually tried, but was it as simple as just replacing a static mesh asset?

Good job! Glad we were of help!

For those who stumble upon similar scenarios:

short version:

I did two things (It was pretty easy)

  1. Replaced the internal render target material with my own
  2. applied that material to the mesh of my own choice

Long version:

The normal WidgetComponent internally directly renders to a RenderTarget and uses this render target with a material (as texture parameter) then applies this material to a plane mesh (It makes the plane mesh in real time).

The material it uses for render target was hard-coded and are /Engine/EngineMaterials/Widget3DPassThrough_xxxx (see UnrealEngine/Engine/Source/Runtime/UMG/Private/Components/WidgetComponent.cpp line 458 and onwards)

Those materials were made unlit meaning the light would have no effect on them nor I could mix ui with other cool material effects. Hence I made my own materials for render targets

So for this proof of concept I made few custom C++ (BP callable) functions that allows me to set the material with which the FWidgetRenderer’s render target is used and another function to grab the dynamic material instance of it back from the component.

On start I set the material of my choice with a render target parameter and then grabbed its dynamic instance from the widget component and applied it to the book.

Ue4 is very flexible , you can extend it to a full fledged custom component and use UV mapping to determine the hit location for the click and other interaction.

Hope this helps people

@ScottSpadea Answered

That +1 !!!

Hi,I am a newcomer to ue4 and c++,could you show me the function code in c++?

Why would you prefer to do this over changing what mesh the WidgetComponent can render on? The way I understand it, you tweak the widgetcomponent to create a material for you to apply on whatever mesh you want but since it also has the ability to tell it what Mesh to render on couldn’t you also tweak that instead preserving all the clicking logic potentially?

Could you give an example how to use umg on materials please i’ve been searching for a simple way to get the output of a widget to materials and so far this is the only thing i found but it’s not clear? Thanks!