Taking Screenshots In-Game In Unreal Engine 4.23

Taking Screenshots In-Game In Unreal Engine 4.23

This is a simple method to take screenshots in-game using Unreal Engine 4.23.

Execute this code somewhere in your project and it will generate a PNG screenshot at the same resolution your game is currently rendering at.

// Generate a filename based on the current date
const FDateTime Now = FDateTime::Now();

// store screenshot in Project directory next to main UProject/EXE based on the build type
const FString ImageDirectory = FString::Printf(TEXT("%s/%s"), *FPaths::ProjectDir(), TEXT("Screenshots"));
const FString ImageDirectory = FString::Printf(TEXT("%s/../%s"), *FPaths::ProjectDir(), TEXT("Screenshots"));

const FString ImageFilename = FString::Printf(TEXT("%s/Screenshot_%d%02d%02d_%02d%02d%02d_%03d.png"), *ImageDirectory, Now.GetYear(), Now.GetMonth(), Now.GetDay(), Now.GetHour(), Now.GetMinute(), Now.GetSecond(), Now.GetMillisecond());

FScreenshotRequest::RequestScreenshot(ImageFilename, false, false);

As a bonus, this screenshot will also appear in a convenient "Screenshots" folder in your project, rather than in the Saved/ directory - making this a little more usable for development and players.

This is better than using a manual capture component because this will go through the same render path as your main game, so will pick up any post-processing effects etc.