How do you save a programmaticly created texture to a file

I programticaly generate a texture and use in in a Dynamic material.

The problem is I would like to test my materials using these programtically generated textures

At runtime I can open the dynamic material and see the texture_parameters that I set, I can open each individual one in the Unreal image editor. However I cannot figure out how to save them to disk for testing or inspection. How can I save textures from a dynamic material Instance, OR how can I save programtically generated textures?

I believe you can use render targets to do this. Here’s a how-to in the UE4 docs that walk you through how to do it:

Basically, you create a render target, create a material (which you already have) and make a BP to bake that material to the render target and output to texture.

I already generated the texture in memory, I want to save it to disk somehow.

Yes, that’s what the linked tutorial shows how to do. It basically renders the material and saves the result to a 2D texture asset that will show up in the content browser when all is said and done.

In the end you should have something like this (where the _Tex file is a texture asset that you can use or export):

https://docs.unrealengine.com/latest/images/Engine/Rendering/RenderTargets/BlueprintRenderTargets/HowTo/CreatingTextures/Create_Textures_06.jpg

Ok this is definitely the right path, but when I click “Create Static Texture” nothing happens…

I ended up using the BluePrint Function ExportRenderTarget to explicitly write the rendertarget to a file. It writes it in .hdr format

hdr is THE format no package can display, how do I change the target to use png format IN BLUEPRINT ?

For those, who are still looking for the solution on exporting any image from the UE4, i managed to export downloaded image(using DownloadImage node) to the .png file by this code

Note: RenderTarget format is super important!

7 Likes

Thanks. that was the great solution but what if is use draw material instead of Draw texture to draw from my material? It’s giving me blank image don’t know why?
image