Skip to content

Instantly share code, notes, and snippets.

@ashe23
Last active January 6, 2026 12:10
Show Gist options
  • Select an option

  • Save ashe23/ec404f4120e62067a595d37804659fbc to your computer and use it in GitHub Desktop.

Select an option

Save ashe23/ec404f4120e62067a595d37804659fbc to your computer and use it in GitHub Desktop.
In Game ScreenShootMaker Unreal Engine
// Fill out your copyright notice in the Description page of Project Settings.
#include "ScreenShootMaker.h"
#include "ImageUtils.h"
#include "Misc/FileHelper.h"
#include "Runtime/Engine/Classes/Engine/World.h"
#include "HighResScreenshot.h"
#include "Runtime/Engine/Classes/Engine/Engine.h"
#include "Runtime/Engine/Classes/Engine/GameViewportClient.h"
#include "Runtime/Engine/Public/Slate/SceneViewport.h"
#include "CustomV.h"
#include "Runtime/Core/Public/Misc/Paths.h"
// Sets default values
AScreenShootMaker::AScreenShootMaker()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
SetActorHiddenInGame(true);
bOverrideSavePath = false;
Resolutions.Add(FVector2D{ 640.0f, 480.f });
Resolutions.Add(FVector2D{ 1280.0f, 800.f });
ScreenShotSavePath = FPaths::ProjectDir() + TEXT("ScreenShoots/");
}
// Called when the game starts or when spawned
void AScreenShootMaker::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AScreenShootMaker::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AScreenShootMaker::MakeScreenShoot()
{
if (GetWorld()->WorldType != EWorldType::Game)
{
UE_LOG(LogTemp, Error, TEXT("Game Must be in StandAlone Game mode to take screenshoots!"));
return;
}
if (!GEngine) return;
if (!GEngine->GameViewport) return;
UGameViewportClient* GameViewport = GEngine->GameViewport;
if (GameViewport)
{
FVector2D ViewportSize;
GameViewport->GetViewportSize(ViewportSize);
FIntRect Rect(0, 0, ViewportSize.X, ViewportSize.Y);
TArray<FColor> ColorBuffer;
FViewport* InViewport = GameViewport->Viewport;
TArray<FColor> Bitmap;
bool bScreenshotSuccessful = GetViewportScreenShot(InViewport, Bitmap, Rect);
if (bScreenshotSuccessful)
{
for (auto& Color : Bitmap)
{
Color.A = 255;
}
FIntVector Size(InViewport->GetSizeXY().X, InViewport->GetSizeXY().Y, 0);
TArray<uint8> CompressedBitmap;
TArray<FColor> dst;
for (auto &Resolution : Resolutions)
{
FString ScreenShotName = ScreenShotSavePath + TEXT("ScreenShot_") + FString::FromInt(Resolution.X) + TEXT("_") + FString::FromInt(Resolution.Y) + TEXT(".png");
FImageUtils::ImageResize(InViewport->GetSizeXY().X, InViewport->GetSizeXY().Y, Bitmap, Resolution.X, Resolution.Y, dst, true);
FImageUtils::CompressImageArray(Resolution.X, Resolution.Y, dst, CompressedBitmap);
FFileHelper::SaveArrayToFile(CompressedBitmap, *ScreenShotName);
}
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("ScreenShot Done!"));
}
}
}
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ScreenShootMaker.generated.h"
class FRenderTarget;
UCLASS()
class UPWORK_API AScreenShootMaker : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AScreenShootMaker();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "HiResScreenMaker")
bool bOverrideSavePath;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "HiResScreenMaker", meta = (EditCondition = "bOverrideSavePath"))
FString ScreenShotSavePath;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "HiResScreenMaker")
TArray<FVector2D> Resolutions;
UFUNCTION(BlueprintCallable, Category = "HiResScreenMaker")
void MakeScreenShoot();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment