Export to Disk Won't Export.

I found out that when Exporting multiple images to disk, sometimes it just won’t work regardless of using Async mode or not.

From my test, it seems that whenever I run the game on a separate window it works fine, but when I run it from the editor or even standalone mode, it doesn’t

My File Directories are valid, and the file names are unique each time, so there’s no overwriting, it just simply will return false when doing the above, unless its run on a separate window and it seems to work pretty much always.

Any help is appreciated. thanks.

1 Like

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