Screenshot to Variable

I have two questions related to my need: i want to save an in-game screenshot in a cpp variable. Do you know any way of doing it? Below i’ll leave two question about the way I’ve thought of doing it.

Question one, the preferred way:
Is there a way to take the screenshot and directly put it in a variable (maybe a UTexture2D) without saving it on the computer?I found out this method GEngine->GameViewport->Viewport->GetRenderTargetTexture()->GetTexture2D();, but it returns a FTexture2DRHIRef that is very low level.

Question two, the plan B: if question one is not possible, is there at least a clever way to get the name of the last saved screenshot after the invocation of GEngine->GameViewport->Viewport->TakeHighResScreenShot(); without rewriting the HighResScreenShot() function? So i will use the path to load it into a texture after the screenshot has been taken.

PS: i’m aware of the existence of FScreenshotRequest but i don’t understand how it should be used properly and if i can use it for my purpose.

Is there any update on this request?

hope for anyone’s answer

You can do this:

void X::Y(USceneCaptureComponent2D * CaptureComponent,
FVector2D vSize)

CaptureComponent->CaptureSource = ESceneCaptureSource::SCS_FinalColorLDR;
CaptureComponent->TextureTarget = NewObject<UTextureRenderTarget2D>();

CaptureComponent->TextureTarget->InitAutoFormat(vSize.X, vSize.Y);

UTextureRenderTarget2D* RenderTarget = CaptureComponent->TextureTarget;
TArray<FColor> Image;
FTextureRenderTargetResource* RenderTargetResource;
Image.AddZeroed(vSize.X * vSize.Y);

RenderTargetResource = RenderTarget->GameThread_GetRenderTargetResource();

FReadSurfaceDataFlags ReadSurfaceDataFlags;

RenderTargetResource->ReadPixels(Image, ReadSurfaceDataFlags);

TArray<uint8> arrRGB;
arrRGB.AddZeroed(vSize.X * vSize.Y * 3);

for (int i = 0; i < Image.Num(); i++) {
	int y = i * 3;
	arrRGB[y] = Image[i].R;
	arrRGB[y + 1] = Image[i].G;
	arrRGB[y + 2] = Image[i].B;


thanks! i solve it!

you can help me ,i don’t how to solve.

hi, have code or speaking ,i don’t understand