x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Is there a way to prompt the player to select a previously saved game file from the saved game directory location manually?

Hi, I'm relatively new to unreal engine and I was wondering if I could get some assistance with something. I've seen tutorials about saving and loading data into a level using the blueprint editor. What I've seen usually involves loading from the save game slot. What I'm wondering is if there's a way to prompt the user to "load game" where the user is able to select a previously saved file present in the saved file location?

Product Version: UE 4.13
Tags:
more ▼

asked Mar 07 '17 at 01:19 AM in Blueprint Scripting

avatar image

Uchiha_Chris_
1 1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

There's no native way to do that in Blueprints. But you can add this functionality very easily with a custom Blueprint node in C++. If you want to avoid using code, then another way would be to save your saves with preset predictable names such as save_01, save_02, then you could use the DoesSaveGameExist node to populate a list of existing saves through iteration (And then include a friendly save name variable in the save itself that serves as the save name the user sees in the list if needed, although that would require accessing each save which may or may not be feasible).

The below code comes from the great Rama, whose Blueprint library I recommend.

Header:

 #pragma once
 
 #include "Kismet/BlueprintFunctionLibrary.h"
 #include "GetSaveFiles.generated.h"
 
 
 UCLASS()
 class PROJECTNAME_API UGetSaveFiles : public UBlueprintFunctionLibrary
 {
     GENERATED_UCLASS_BODY()
 
 
     UFUNCTION(BlueprintPure, Category = SaveFunctions)
     static void SaveGameObject_GetAllSaveSlotFileNames(TArray<FString>& FileNames);
 
 };


Source:

 // Code by Rama
 
 #include "ProjectName.h"
 #include "GetSaveFiles.h"
 
 template <class FunctorType>
 class PlatformFileFunctor : public IPlatformFile::FDirectoryVisitor    //GenericPlatformFile.h
 {
 public:
 
     virtual bool Visit(const TCHAR* FilenameOrDirectory, bool bIsDirectory) override
     {
         return Functor(FilenameOrDirectory, bIsDirectory);
     }
 
     PlatformFileFunctor(FunctorType&& FunctorInstance)
         : Functor(MoveTemp(FunctorInstance))
     {
     }
 
 private:
     FunctorType Functor;
 };
 
 template <class Functor>
 PlatformFileFunctor<Functor> MakeDirectoryVisitor(Functor&& FunctorInstance)
 {
     return PlatformFileFunctor<Functor>(MoveTemp(FunctorInstance));
 }
 
 static bool GetFiles(const FString& FullPathOfBaseDir, TArray<FString>& FilenamesOut, bool Recursive = false, const FString& FilterByExtension = "")
 {
     //Format File Extension, remove the "." if present
     const FString FileExt = FilterByExtension.Replace(TEXT("."), TEXT("")).ToLower();
 
     FString Str;
     auto FilenamesVisitor = MakeDirectoryVisitor(
         [&](const TCHAR* FilenameOrDirectory, bool bIsDirectory)
     {
         //Files
         if (!bIsDirectory)
         {
             //Filter by Extension
             if (FileExt != "")
             {
                 Str = FPaths::GetCleanFilename(FilenameOrDirectory);
 
                 //Filter by Extension
                 if (FPaths::GetExtension(Str).ToLower() == FileExt)
                 {
                     if (Recursive)
                     {
                         FilenamesOut.Push(FilenameOrDirectory); //need whole path for recursive
                     }
                     else
                     {
                         FilenamesOut.Push(Str);
                     }
                 }
             }
 
             //Include All Filenames!
             else
             {
                 //Just the Directory
                 Str = FPaths::GetCleanFilename(FilenameOrDirectory);
 
                 if (Recursive)
                 {
                     FilenamesOut.Push(FilenameOrDirectory); //need whole path for recursive
                 }
                 else
                 {
                     FilenamesOut.Push(Str);
                 }
             }
         }
         return true;
     }
     );
     if (Recursive)
     {
         return FPlatformFileManager::Get().GetPlatformFile().IterateDirectoryRecursively(*FullPathOfBaseDir, FilenamesVisitor);
     }
     else
     {
         return FPlatformFileManager::Get().GetPlatformFile().IterateDirectory(*FullPathOfBaseDir, FilenamesVisitor);
     }
 }
 
 UGetSaveFiles::UGetSaveFiles(const FObjectInitializer& ObjectInitializer)
     : Super(ObjectInitializer)
 {
 
 }
 
 void UGetSaveFiles::SaveGameObject_GetAllSaveSlotFileNames(TArray<FString>& FileNames)
 {
     FileNames.Empty();
     FString Path = FPaths::ConvertRelativePathToFull(FPaths::GameSavedDir()) + "SaveGames";
     GetFiles(Path, FileNames);
 }


This will return an array of save names, which you could then add to a list for the user to select a save. This is what I am doing in the below example: alt text

saves.jpg (279.4 kB)
more ▼

answered Mar 07 '17 at 11:37 AM

avatar image

Mosel3y
1.8k 49 20 67

avatar image Uchiha_Chris_ Mar 07 '17 at 11:55 PM

Thanks so much for your help

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question