HighresScreenshot, how to avoid?

Hello and thank you for reading.

I have created a Plugin for Unreal engine that saves an image buffer (BRGA-Pixel-Array) to a file instead of a PNG, as the standard HighresScreenCapture method does.

This is done by adding a Lamda-Function to the Viewport->OnscreenCaptured-Event. Now this worked fine until Unreal Engine 5.6. With 5.6 the PNG is written before my plugin function is even called. This results in both a PNG and my own BGRA-File.

Any idea what to do? Thank you so much!

void UUnrealBPLibrary::MY_HighResCapture(FString filePath, FString fileName)
{

// combine the string to get the path for the file
    IFileManager& FileManager = IFileManager::Get();
    FString TargetPath = FPaths::Combine(filePath, fileName) + ".pixel";

// Check the context is present
    UWorld* World = GEngine->GameViewport->GetWorld();
    if (!World)
    {
        UE_LOG(LogTemp, Error, TEXT("World is null!"));
        return;
    }

    UGameViewportClient* ViewportClient = World->GetGameViewport();
    if (!ViewportClient)
    {
        UE_LOG(LogTemp, Error, TEXT("ViewportClient is null!"));
        return;
    }

    GIsHighResScreenshot = true;
    FDateTime StartTime = FDateTime::Now();

// Append the Lambda-function to OnScreenshotCaptured
    ViewportClient->OnScreenshotCaptured().AddLambda([filePath, fileName, StartTime, OriginalViewportCaptured, ViewportClient](int32 SizeX, int32 SizeY, const TArray<FColor>& Bitmap)
        {
            SaveBitmapToBinaryFile(filePath, fileName, Bitmap, SizeX, SizeY);
            int64 iSizeNow = SizeX * SizeY * 4;
            double dMsecs = (FDateTime::Now() - StartTime).GetTotalMilliseconds();
            UE_LOG(LogTemp, Warning, TEXT("HighResCapture took %f msecs, file size %lld byte, fileName %s%s.pixel"), dMsecs, iSizeNow, *filePath, *fileName);
        });

    GAreScreenMessagesEnabled = false;
    ViewportClient->Viewport->TakeHighResScreenShot();
}