How To Convert Texture 2DDynamic to just Texture 2D?

My situation :

I’m trying to download and display some images on my UI.
I don’t want to redownload the images every time I run the game.
hence I want to export the downloaded Image to Disk after the first time and then reuse it.
But “Export To Disk” node is not working

2022-07-20 01_01_35-EndlessRunner - Unreal Editor

It throws the following error in the Output Log

LogScript: Error: Script Msg: Unsupported texture format.

So I tried to use “Export Texture2D” instead. It works with normal Texture 2D inputs, but the “Download Image” node returns a Texture 2DDynamic, which doesn’t work with the “Export Texture2D” node.

What I’m looking for :

  • way to Convert Texture 2DDynamic to Texture 2D

OR

  • way to Export the Downloaded Texture 2DDynamic.
1 Like

Hi @Extrone !

After spending some time trying to convert a Texture2D into a Texture2DDynamic and vice-versa. I figured out that it was not possible directly, that is because both classes inherit from the same class “UTexture”. Then I tried to create a new Texture2D using the values from Texture2DDynamic, I had problems but it seems possible on c++, on blueprints on the other side, it doesn’t look like it’s going to be easy.

So a new approach came into mind, what if we try to parse the Texture of the Brush? Something like this

I can’t test it right now, as I don’t have a Dynamic Texture, but hopefully, it works, as the brush is being set right before calling this.

Tell me if it works! Kind Regards,
Raimundo

2 Likes

Thanks for the insight
I tried to parse the Texture of the Brush like that, but the Texture2D Cast Failed.
I’ll look into creating a new Texture2D in C++

I think I may have found some posts that could help you on that quest, UE4 create texture from C++ - Stack Overflow and UE4 - Save a procedurally generated texture as a new asset - Isara Tech. .

FTexture2DDynamicCreateInfo Texture2DDynamicCreateInfo;
	Texture2DDynamicCreateInfo.Filter = Texture->Filter;
	Texture2DDynamicCreateInfo.Format = Texture->GetPixelFormat();
	Texture2DDynamicCreateInfo.bIsResolveTarget = false;
	Texture2DDynamicCreateInfo.bSRGB = Texture->SRGB;
	DynamicTexture = UTexture2DDynamic::Create(Texture->GetSizeX(), Texture->GetSizeY(),
	                                                                 Texture2DDynamicCreateInfo);
	DynamicTexture->SetResource(Texture->GetResource());
	DynamicTexture->SetFlags(Texture->GetFlags());
	DynamicTexture->SetLinker(Texture->GetLinker(), Texture->GetLinkerIndex(), true);
	DynamicTexture->SetExternalPackage(Texture->GetExternalPackage());
	DynamicTexture->SetLightingGuid();
	

	NewTexture = UTexture2D::CreateTransient(DynamicTexture->SizeX, DynamicTexture->SizeY, DynamicTexture->Format);
	NewTexture->SetResource(DynamicTexture->GetResource());
	NewTexture->SetFlags(DynamicTexture->GetFlags());
	NewTexture->SetLinker(DynamicTexture->GetLinker(), DynamicTexture->GetLinkerIndex(), true);
	NewTexture->SetExternalPackage(DynamicTexture->GetExternalPackage());
	NewTexture->SetLightingGuid();
	// NewTexture should be equal or similar to Texture

I’ve been trying to convert a Texture2D into a Texture2DDynamic and then create a new Texture2D from that Texture2DDynamic, but I’m not that familiar with textures and how they are built. This compiles, but whenever you want to look at it on the editor (select the actor in the world outliner) it crashes. I suspect it should be something similar but with the knowledge of the posts I linked before.

1 Like

This is works Great job

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.