Export to Disk PNG results in blank

Hi,

I am trying to export render target as PNG images from C++. I can see the render target properly on a surface, however, ExportToDisk results in a blank image. Any pointers on debugging this?

Here’s the code to I used to setup the render target and screen capture component.

void AScreenCaptureCameraActor::SetupSceneCaptureComponment() {

	UCameraComponent* currentCamera = this->GetCameraComponent();
	FMinimalViewInfo minimalViewInfo;
	currentCamera->GetCameraView(0, minimalViewInfo); // first argument is delta time.

	mSceneCaptureComponent = mSceneCaptureActor->GetCaptureComponent2D();
	mSceneCaptureComponent->SetCameraView(minimalViewInfo);
	mSceneCaptureComponent->bAlwaysPersistRenderingState = false;
	mSceneCaptureComponent->CaptureSource = ESceneCaptureSource::SCS_FinalColorLDR;
	mSceneCaptureComponent->bCaptureOnMovement = false;
	mSceneCaptureComponent->bCaptureEveryFrame = false;
	mSceneCaptureComponent->MaxViewDistanceOverride = -1.0f;
	mSceneCaptureComponent->bAutoActivate = true;
	mSceneCaptureComponent->DetailMode = EDetailMode::DM_High;
}

void AScreenCaptureCameraActor::CaptureScene() {
	FTransform cameraWorldTransform = this->GetCameraComponent()->GetComponentTransform();
	mSceneCaptureComponent->SetWorldTransform(cameraWorldTransform);

	UTextureRenderTarget2D* renderTarget2D = NewObject<UTextureRenderTarget2D>();
	renderTarget2D->ClearColor = FLinearColor::Blue;
	renderTarget2D->InitCustomFormat(IMG_WIDTH, IMG_HEIGHT, PF_B8G8R8A8, true);
	renderTarget2D->RenderTargetFormat = ETextureRenderTargetFormat::RTF_RGBA8;

	UCameraComponent* currentCamera = this->GetCameraComponent();
	FMinimalViewInfo minimalViewInfo;
	currentCamera->GetCameraView(0, minimalViewInfo); // first argument is delta time.

	mSceneCaptureComponent->SetCameraView(minimalViewInfo);
	mSceneCaptureComponent->bAlwaysPersistRenderingState = false;
	mSceneCaptureComponent->CaptureSource = ESceneCaptureSource::SCS_FinalColorLDR;
	mSceneCaptureComponent->TextureTarget = renderTarget2D;

	mSceneCaptureComponent->CaptureScene();

	this->mScreenNeedsToBeCaptured = true;
}

Try with RTF RGBA8 sRGB if that does anything.

Thank you for the suggestion. It’s still blank with sRGB. Only difference i saw is that without the srgb, unreal editor was reporting “Detected Source Alpha: 1”. It does not say anything anymore.

I noticed one thing that the dumped image has all the channel values set to 0. I am now wondering whether the capturing timing has to do anything with it. Any chance that I tried to save before renderTarget got populated? Or may be it got cleared. I am still new with Unreal Engine. Any pointers on the lifecycle practices that I should watch out for?

Try to make the same setting as this one, it seem other people were facing the same issue Saving render target to .png and exporting - #6 by Arodi007