Announcement

Collapse
No announcement yet.

Savegame Menu With Screenshot Thumbnails

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

    Savegame Menu With Screenshot Thumbnails

    Hello everyone!

    So for a while now I've been wondering how to create something like this. It seems like such a simple tast that is used in a lot of games, but so far I couldn't really find a tutorial on it.
    I currently have a project that uses a savegame to save certain variables. So far it only uses one, but I'd like to be able to save up multiple states and have a little thumbnail of the current camera for it aswell.
    So what would be the quickest way to add that functionality to an existing savegame system?

    tl;dr
    How do I save a screenshot of the current scene and use it as a thumbnail for the save states in my HUD?

    #2
    Originally posted by Seirei View Post
    Hello everyone!

    So for a while now I've been wondering how to create something like this. It seems like such a simple tast that is used in a lot of games, but so far I couldn't really find a tutorial on it.
    I currently have a project that uses a savegame to save certain variables. So far it only uses one, but I'd like to be able to save up multiple states and have a little thumbnail of the current camera for it aswell.
    So what would be the quickest way to add that functionality to an existing savegame system?

    tl;dr
    How do I save a screenshot of the current scene and use it as a thumbnail for the save states in my HUD?
    I'm not familiar with creating save games, though there are plenty of tutorials for that, but you could probably add scene capture 2d component (have it attached to your camera and give it the same transform so that it captures from the same view as your in game camera) in your character blueprint, and each time you save, have it update the capture, and input that capture in an instanced material that's assigned to a menu widget image piece.

    Comment


      #3
      Hi hippowombat,

      I thought about doing something like that, but so far I wasn't sure if the texture from the scene capture would actually be saved. I noticed that a scene capture 2d loses it's texture on restart. At least back in 4.8 I had that happening. Guess I'll just have to try it out then.

      Comment


        #4
        Scene capture -> Texture2D -> save to savegame
        Github - YouTube - Unreal Slackers - KITATUS

        Comment


          #5
          Will do! Thanks!

          Comment


            #6
            Hello.
            Did you finish this function? I also need to do a similar function, can share the experience? Thanks...

            Comment


              #7
              Sadly it didn't work as expected and we ended up using C++ to save and load the images directly to the HDD.

              Comment


                #8
                Can you plz share how to save and load images using c++? Thanks !
                CG Supervisor at https://darulsolutions.com | Download Demo | Car Configurator | Interactive Arch Viz | Facebook | Youtube | Linkedin | Artstation

                Comment


                  #9
                  i know this is old, but I am trying to do the same thing, does anyone know of a solution?

                  Comment


                    #10
                    JohnADaniels. see my post, if you are still interesting in it.

                    Comment


                      #11
                      I looked at the the post but is did not show how to make the screenshot with BluePrint.




                      Originally posted by kup guitarplayer View Post
                      JohnADaniels. see my post, if you are still interesting in it.

                      Comment


                        #12
                        Here's how I do it with a custom event in my spectator pawn (you would use whatever player pawn you use). My Game Instance calls this event, and this saves the screenshot with whatever file name I designate. My Save Game has a string variable that contains this file name, and my load game widget gets that screenshot file name and imports the screenshot file as a Texture 2D.

                        Comment


                          #13
                          Originally posted by KelbyVP View Post
                          Here's how I do it with a custom event in my spectator pawn (you would use whatever player pawn you use). My Game Instance calls this event, and this saves the screenshot with whatever file name I designate. My Save Game has a string variable that contains this file name, and my load game widget gets that screenshot file name and imports the screenshot file as a Texture 2D.
                          What node do you use to import the screen as a texture 2D?

                          Comment


                            #14
                            My C++ code is below for importing the save file as a Texture2D. (Fair warning, I changed the way I save these screenshots pretty dramatically; I'll post that separately.) My apologies in advance that I can't seem to figure out how to post code correctly:


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

                            UTexture2D* USaveGametFunctionLibrary::ImportScreenshotSave(UObject* WorldContextObject, const FString& SaveGameName)
                            {
                            FString ScreenshotFile = GetSaveGameScreenshotName(SaveGameName);

                            if (FPaths::FileExists(ScreenshotFile))
                            {
                            return FImageUtils::ImportFileAsTexture2D(ScreenshotFile);
                            }

                            return nullptr;
                            }

                            Comment


                              #15
                              Here's my new approach to saving the screenshots. First, the blueprint:

                              Click image for larger version

Name:	ScreenshotSave.png
Views:	657
Size:	72.1 KB
ID:	1719498
                              Next, the C++ SaveScreenshot function:


                              bool USaveGametFunctionLibrary::SaveScreenshot(
                              class USceneCaptureComponent2D* Target,
                              const FLinearColor ClearColour,
                              const FString SaveGameName)
                              {
                              if ((Target == nullptr) || (Target->TextureTarget == nullptr))
                              {
                              return false;
                              }

                              FRenderTarget* RenderTarget = Target->TextureTarget->GameThread_GetRenderTargetResource();
                              if (RenderTarget == nullptr)
                              {
                              return false;
                              }

                              TArray<FColor> RawPixels;

                              // Format not supported - use PF_B8G8R8A8.
                              if (Target->TextureTarget->GetFormat() != PF_B8G8R8A8)
                              {
                              UE_LOG(LogTemp, Warning, TEXT("Format not supported - use PF_B8G8R8A8."));
                              return false;
                              }

                              if (!RenderTarget->ReadPixels(RawPixels))
                              {
                              return false;
                              }

                              // Convert to FColor.
                              FColor ClearFColour = ClearColour.ToFColor(false); // FIXME - want sRGB or not?

                              for (auto& Pixel : RawPixels)
                              {
                              // Switch Red/Blue changes.
                              const uint8 PR = Pixel.R;
                              const uint8 PB = Pixel.B;
                              Pixel.R = PB;
                              Pixel.B = PR;

                              // Set alpha based on RGB values of ClearColour.
                              Pixel.A = ((Pixel.R == ClearFColour.R) && (Pixel.G == ClearFColour.G) && (Pixel.B == ClearFColour.B)) ? 0 : 255;
                              }

                              IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
                              TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);

                              const int32 Width = Target->TextureTarget->SizeX;
                              const int32 Height = Target->TextureTarget->SizeY;

                              if (ImageWrapper.IsValid() && ImageWrapper->SetRaw(&RawPixels[0], RawPixels.Num() * sizeof(FColor), Width, Height, ERGBFormat::RGBA, 8))
                              {
                              FFileHelper::SaveArrayToFile(ImageWrapper->GetCompressed(), *GetSaveGameScreenshotName(SaveGameName));
                              return true;
                              }

                              return false;
                              }

                              Comment

                              Working...
                              X