Taking screenshot for save slot thumbnail

Hi, I am trying to take a screenshot of the current view when the user saves the sceen so I can display a thumbnail for the loading part. The best solution I have found so far is to use a scene capture 2d to take a capture and save it to a render target. This works as it is suposed to, because I can see the thumbnail of the render target updating in the editor. The problem I have is that I don’t know how to retreive this image so that I can save it to a save slot. Is it possible to somehow convert the render target into a Texture 2D or something similar so that it can be put in a save slot object? Or is there any better way to do this?

Thanks

I am needing to know the same thing, did you ever get this figured out?

Take a look at this

https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/4014-39-rama-s-extra-blueprint-nodes-for-you-as-a-plugin-no-c-required/page41

Thank you Orkney!

It’s possible, I did it about 2 days ago. It’s neither too hard, nor “easy money”. Yes, it’s possible to write a captured image from “SceneCaptureComponent2D” to the saving game slot, and loading this image back. But, as for me, better way would be, if you do an image with some sketch of your level. At least, I decided to choose this way. It has such advantages, as:

  • using a statical image (brush material) much easier than headache with “SceneCaptureComponent2D”;
  • you do not need to create any additional necessary components (like “Render target” and “Material” - they costs RAM);
  • you do not need to control your “SceneCaptureComponent2D” camera (enabling it for the moment of saving, and disabling after save).

If someone need, I can try to record a little test video with this released idea.

By the way, I BPed it only by my hands, without using any plugins. Vanilla BP - nothing more.

Yea, i(and most likely alot of others too) would be really interested in doing this only in BP, without C++ or any third party plugins. :slight_smile:

HEGI, maybe I was not correct:I can record a final video, but not a tutorial, because it’s too complicated to explain, but not to do. To record a real tutorial, I need much more time, than I have for now.

No problem, it seems too complicated to do in blueprint anyway. I have done it in C++ now, wich is very straightforward and clean.
It saves a thumbnail, based on the name of your save game file. So you don’t need to save any image data or file path’s there.
You just need to pass a render target to the export.

If anybody is interested, here is complete code from my function lib. Just need to merge it yourself. :slight_smile:

H



    static FString SaveGameDir(const FString& SaveGameName);

    UFUNCTION(BlueprintCallable, Category = "Rendering", meta = (WorldContext = "WorldContextObject"))
    static UTexture2D* ImportSaveThumbnail(UObject* WorldContextObject, const FString& SaveGameName);

    UFUNCTION(BlueprintCallable, Category = "Rendering", meta = (Keywords = "ExportTexture2D", WorldContext = "WorldContextObject"))
    static void ExportSaveThumbnailRT(UObject* WorldContextObject, UTextureRenderTarget2D* TextureRenderTarget, const FString& SaveGameName);

    UFUNCTION(BlueprintCallable, Category = "Rendering", meta = (Keywords = "ExportTexture2D", WorldContext = "WorldContextObject"))
    static void DeleteSaveThumbnail(UObject* WorldContextObject, const FString& SaveGameName);


CPP



FString UHelperFunctionLibrary::SaveGameDir(const FString& SaveGameName)
{
    return FPaths::ProjectSavedDir() + TEXT("SaveGames/") + SaveGameName + TEXT(".png");
}

UTexture2D* UHelperFunctionLibrary::ImportSaveThumbnail(UObject* WorldContextObject, const FString& SaveGameName)
{
    FString SaveFile = SaveGameDir(SaveGameName);

    //Suppress warning messages when we dont have a thumb yet.
    if (FPaths::FileExists(SaveFile))
    {
        return FImageUtils::ImportFileAsTexture2D(SaveFile);
    }

    return nullptr;
}

void UHelperFunctionLibrary::ExportSaveThumbnailRT(UObject* WorldContextObject, UTextureRenderTarget2D* TextureRenderTarget, const FString& SaveGameName)
{
    FString SaveFile = SaveGameDir(SaveGameName);
    FText PathError;
    FPaths::ValidatePath(SaveFile, &PathError);

    if (!TextureRenderTarget)
    {
        FMessageLog("Blueprint").Warning(LOCTEXT("ExportSaveThumbnailRT_InvalidTextureRenderTarget", "ExportRenderTarget: TextureRenderTarget must be non-null."));
    }
    else if (!TextureRenderTarget->Resource)
    {
        FMessageLog("Blueprint").Warning(LOCTEXT("ExportSaveThumbnailRT_ReleasedTextureRenderTarget", "ExportRenderTarget: render target has been released."));
    }
    else if (!PathError.IsEmpty())
    {
        FMessageLog("Blueprint").Warning(FText::Format(LOCTEXT("ExportSaveThumbnailRT_InvalidFilePath", "ExportRenderTarget: Invalid file path provided: '{0}'"), PathError));
    }
    else if (SaveGameName.IsEmpty())
    {
        FMessageLog("Blueprint").Warning(LOCTEXT("ExportSaveThumbnailRT_InvalidFileName", "ExportRenderTarget: FileName must be non-empty."));
    }
    else
    {
        FArchive* Ar = IFileManager::Get().CreateFileWriter(*SaveFile);

        if (Ar)
        {
            FBufferArchive Buffer;

            bool bSuccess = FImageUtils::ExportRenderTarget2DAsPNG(TextureRenderTarget, Buffer);

            if (bSuccess)
            {
                Ar->Serialize(const_cast<uint8*>(Buffer.GetData()), Buffer.Num());
            }

            delete Ar;
        }
        else
        {
            FMessageLog("Blueprint").Warning(LOCTEXT("ExportSaveThumbnailRT_FileWriterFailedToCreate", "ExportRenderTarget: FileWrite failed to create."));
        }
    }
}

void UHelperFunctionLibrary::DeleteSaveThumbnail(UObject* WorldContextObject, const FString& SaveGameName)
{
    FString SaveFile = SaveGameDir(SaveGameName);
    IFileManager::Get().Delete(*SaveFile, true, false, true);
}


2 Likes

I’ll try to record some kind of a “BP hint video” soon. But, looks like with using a C++, it gets really less :rolleyes: .

Did you ever record a video on how to screenshots for thumbnails?

Hey there! I’ve tried spawning SceneCapture2D and then rendering the scene capture to a render target. I was not able to save the resulting Texture2D to a SaveGame file directly (was resulting in a black image) but I was able to save the Texture2D to an actual file on the HDD. I know using C++, this is a rather easy task but I’ve managed to do it in Blueprints only since there were a lot of people interested.

Save binary image to      HDD: Save slot thumbnail image posted by anonymous | blueprintUE | PasteBin For Unreal Engine
Load binary image from HDD: Load slot thumbnail image posted by anonymous | blueprintUE | PasteBin For Unreal Engine

This is tested on Windows with UE 4.27. I would be happy if someone confirms it works on other platforms as well. Cheers!

Mind making that video? I would love to see how you implement this into a main menu/game save system

when I click this site,I come to a page,it says " Oops! That page doesn’t exist or is private."

Thanks,your method is effective,but why can’t directly convert the TextureCapture2d to Texture2D,I guess the reason is that texture2d need a uasset stored on hard drive,so it’s necessary to create a file on hard drive.

Hi, look at this plugin on UE Marketplace, it may have some help!
Screenshot as Texture2D in Code Plugins - UE Marketplace (unrealengine.com)