[HELP/BASIC] Taking a screenshot and display it

Well i am new to c++ followed some tutorials and started programming.

I founded this function: FScreenshotRequest::RequestScreenshot();

So this is the code I wrote:

void UMyBlueprintFunctionLibrary::TakeScreenshot()
{
UGameViewportClient::OnScreenshotCaptured().AddDynamic(this, &UMyBlueprintFunctionLibrary::OnScreenShotCaptured);

FScreenshotRequest::RequestScreenshot(true);

if (GEngine)
    GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "Tried to take screenshot ");

}

As you can see on the docs it says:
Requests a new screenshot. Screenshot can be read from memory by subscribing to the ViewPort’s OnScreenshotCaptured delegate.

I try to do this without any success please help me.

UGameViewportClient::OnScreenshotCaptured().AddDynamic(this, &UMyBlueprintFunctionLibrary::OnScreenShotCaptured); this is not the right way i get the folowing error:

Error (active) class “TMulticastDelegate<void, int32, int32, const TArray<FColor, FDefaultAllocator> &>” has no member “__Internal_AddDynamic” ARtest d:\Unreal projects\ARtest\Source\ARtest\MyBlueprintFunctionLibrary.cpp 9

is OnScreenShotCaptured marked as a UFUNCTION?

Nope but i’ve added it right now and the error stays the same this is my header file:


// Copyright Menno van Hout & Artsis

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "MyBlueprintFunctionLibrary.generated.h"

/**
 * 
 */
UCLASS()
class ARTEST_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

public:
    UFUNCTION(BlueprintCallable, Category = "Test")
    void TakeScreenshot();

    //static FOnScreenshotCaptured & OnScreenshotCaptured();
    UFUNCTION(Category = "Test")
    void OnScreenShotCaptured(int32 InSizeX, int32 InSizeY, const TArray<FColor>& InImageData);
};

UGameViewportClient::OnScreenshotCaptured is a MulticastDelegate and AddDynamic does not work with it, you should use AddUObject or AddStatic instead

Could you give me an example if i change my line to this:


UGameViewportClient::OnScreenshotCaptured().AddStatic(this, &UMyBlueprintFunctionLibrary::OnScreenShotCaptured);

Is thorwing this error:

I might be late but I will drop here my findings in case it’s useful for future readers.

From what I’ve seen, to get this to work you need to declare in your .h file:

static void ScreenshotCaptured(int32 Width, int32 Height, const TArray<FColor>& Bitmap);

in your .cpp you need:

UGameViewportClient::OnScreenshotCaptured().AddStatic(&ScreenshotCaptured);

With this, the delegate works and triggers when the screenshot has been generated. Don’t ask me why it requires these parameters to work, but it just does.

Got the info lurking around chinese websites and looking at how they implemented it:
https://blog.csdn.net/yb0022/article/details/76034181
https://blog.csdn.net/u014532636/article/details/80004616

1 Like