Save render target to file

I’m working on a script for the last week that takes a series of images and saves them as .png/.jpeg to the drive

My method is as follows:

From a CameraActor object:

  1. Initialize a USceneCaptureComponent2D, then an FTextureRenderTarget2DResource
  2. Set the render target variable of the USceneCaptureComponent2D to the FTextureRenderTarget2DResource
  3. set the setCameraView() of the USceneCaptureComponent2D to the getCameraView() of the CameraActor camera component
  4. ??? Save to file

I’ve looked at several solutions online and they tend all be outdated, for example this solution here uses FHighResolutionScreenshotConfig.SaveImage(), which is removed in UE4.21:

My only other option would be:

  1. set the readPixels() of the FTextureRenderTarget2DResource to a buffer
  2. Every tick: Save the contents of the buffer to a file using a c++ png library

Hello! You can use RenderTarget with ExportRenderTarget2DAsPNG method (FImageUtils | Unreal Engine Documentation). Also take a look at Blueprint nodes Export Render Target and Export Texture 2D.

1 Like