I wrote a blueprint function library code for my game that converts “Render Target 2D” to “Texture2D” object. It works correctly in editor mode but not in standalone mode. How can I solve this problem.
This is the code I used:
if (!RenderTarget) return nullptr;
FTextureRenderTargetResource* RTResource = RenderTarget->GameThread_GetRenderTargetResource();
FReadSurfaceDataFlags ReadPixelFlags(RCM_UNorm);
ReadPixelFlags.SetLinearToGamma(false);
TArray<FColor> OutBMP;
RTResource->ReadPixels(OutBMP, ReadPixelFlags);
UTexture2D* Texture = UTexture2D::CreateTransient(RenderTarget->SizeX, RenderTarget->SizeY);
if (!Texture) return nullptr;
void* TextureData = Texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
FMemory::Memcpy(TextureData, OutBMP.GetData(), OutBMP.Num() * sizeof(FColor));
Texture->PlatformData->Mips[0].BulkData.Unlock();
Texture->UpdateResource();
return Texture;