Export to Disk Won't Export.

I encountered something like that too, trying to export 2 (or more) textures as .png files using ExportToDisk, in the same tick (or, more precisely, in a loop). OnComplete delegate was returning false for the second texture.

Then I looked at the C++ implementation of ExportToDisk, and found that it only returns false if texture format is not supported, which in my case was R8G8B8A8 and was okay (make sure to set CompressionSettings to VectorDisplacementMap or UserInterface2D in your texture asset, so that it can be exported in .png). Or when the following checks do not pass:

if (!InTexture || !InTexture->Resource || !InTexture->Resource->TextureRHI)
	{
		FFrame::KismetExecutionMessage(TEXT("Invalid texture supplied."), ELogVerbosity::Error);
		AsyncTask(ENamedThreads::GameThread, [OnCompleteWrapper] { OnCompleteWrapper(false); });
		return;
	}

	FTexture2DRHIRef Texture2D = InTexture->Resource->TextureRHI->GetTexture2D();
	if (!Texture2D)
	{
		FFrame::KismetExecutionMessage(TEXT("Invalid texture supplied."), ELogVerbosity::Error);
		AsyncTask(ENamedThreads::GameThread, [OnCompleteWrapper] { OnCompleteWrapper(false); });
		return;
	}

I assumed that the texture is not immediately ready for being read from, after it is loaded with LoadAsset.
So, I added a C++ method “IsTextureSafeToReadFrom()” in a BlueprintFunctionLibrary
bool UDG_BlueprintFunctionLibrary::IsTextureSafeToReadFrom(UTexture* Texture)
{
if (!Texture || !Texture->Resource || !Texture->Resource->TextureRHI)
{
return false;
}

    return true;
}

to let me know when it is ready for ExportToDisk. I keep calling it every frame, and once it returns true, call ExportToDisk.

Seems to work now.

2 Likes