Announcement

Collapse
No announcement yet.

Taking screenshot for save slot thumbnail

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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

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

    Comment


      #3
      Take a look at this

      https://forums.unrealengine.com/deve...equired/page41
      My Game Frontier Devblog HERE

      Comment


        #4
        Thank you Orkney!

        Comment


          #5
          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.
          Last edited by kup guitarplayer; 08-30-2018, 10:20 AM.

          Comment


            #6
            Originally posted by back0rifize View Post
            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.
            Michael Hegemann - https://twitter.com/HegiDev

            Marketplace Content
            Easy Multi Save
            Mobile Touch Navigation
            Retro 3D Toolkit

            Comment


              #7
              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.

              Comment


                #8
                Originally posted by back0rifize View Post
                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.

                H
                Code:
                    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
                Code:
                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);
                }
                Last edited by HEGI; 08-31-2018, 07:36 AM.
                Michael Hegemann - https://twitter.com/HegiDev

                Marketplace Content
                Easy Multi Save
                Mobile Touch Navigation
                Retro 3D Toolkit

                Comment


                  #9
                  I'll try to record some kind of a "BP hint video" soon. But, looks like with using a C++, it gets really less .

                  Comment


                    #10
                    Originally posted by kup guitarplayer View Post
                    I'll try to record some kind of a "BP hint video" soon. But, looks like with using a C++, it gets really less .
                    Did you ever record a video on how to screenshots for thumbnails?

                    Comment

                    Working...
                    X