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 get all savegames in BP

I was wondering if there is a way to get all savegames in the savegame directory, without having to have a savegame with the list of your savegames?

So far I have only seen it done in C++.

What I would like, is to be able to copy/paste savegames to the folder, and then dynamically load them.

Product Version: Not Selected
Tags:
more ▼

asked Dec 11 '14 at 08:53 AM in Blueprint Scripting

avatar image

DekanTrue
28 4 7 10

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

3 answers: sort voted first

This code should work for any platform.

.h

     /** returns a list of all save games in /Saved/SaveGames folder, without the .sav extension (filename only) */
     UFUNCTION(BlueprintPure, Category = Game)
     static TArray<FString> GetAllSaveGameSlotNames();

.cpp

 #include "Paths.h"
 #include "PlatformFile.h"
 #include "PlatformFilemanager.h"
 
 TArray<FString> USnakesBlueprintFunctionLibrary::GetAllSaveGameSlotNames()
 {
     //////////////////////////////////////////////////////////////////////////////
     class FFindSavesVisitor : public IPlatformFile::FDirectoryVisitor
     {
     public:
         FFindSavesVisitor() {}
 
         virtual bool Visit(const TCHAR* FilenameOrDirectory, bool bIsDirectory)
         {
             if (!bIsDirectory)
             {
                 FString FullFilePath(FilenameOrDirectory);
                 if (FPaths::GetExtension(FullFilePath) == TEXT("sav"))
                 {
                     FString CleanFilename = FPaths::GetBaseFilename(FullFilePath);
                     CleanFilename = CleanFilename.Replace(TEXT(".sav"), TEXT(""));
                     SavesFound.Add(CleanFilename);
                 }
             }
             return true;
         }
         TArray<FString> SavesFound;
     };
     //////////////////////////////////////////////////////////////////////////////
 
     TArray<FString> Saves;
     const FString SavesFolder = FPaths::GameSavedDir() + TEXT("SaveGames");
 
     if (!SavesFolder.IsEmpty())
     {
         FFindSavesVisitor Visitor;
         FPlatformFileManager::Get().GetPlatformFile().IterateDirectory(*SavesFolder, Visitor);
         Saves = Visitor.SavesFound;
     }
 
     return Saves;
 }

If you don't know what to do with this, look up in the wiki: "C++ blueprint function library tutorial".

more ▼

answered Jun 25 '17 at 08:04 PM

avatar image

Ixiguis
1.2k 58 61 254

avatar image Reactant Jul 23 '17 at 04:03 PM

I'm not very good at C++, could someone explain why when i try and compile the above code i get an error saying USnakesBlueprintFunctionLibrary is not a class, If anyone could point me in the right direction id appreciate it

avatar image Ixiguis Jul 23 '17 at 05:08 PM

If you don't know what to do with this, look up in the wiki: "C++ blueprint function library tutorial".

avatar image Reactant Jul 24 '17 at 03:14 PM

i have looked that up but all i find is ramas tutorial and he doesnt explain much of anything

avatar image LatFoued Nov 05 '17 at 01:35 PM

Thanks! This works perfectly.

avatar image dollon Aug 08 '19 at 11:14 AM

You my sir are a life Saver.

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

A direct solution. WINDOWS ONLY. In my static helper blueprint class.....

---- .h -----

     UFUNCTION(BlueprintCallable, Category = TDLHelpers)
         static TArray<FString> GetAllSaveGameSlotNames();
 

---- .cpp -----

 #include "PlatformFeatures.h"
 #include "GameFramework/SaveGame.h"
 
 ...
 
 TArray<FString> UtdlBlueprintHelpers::GetAllSaveGameSlotNames()
 {
     TArray<FString> ret;
 
     ISaveGameSystem* SaveSystem = IPlatformFeaturesModule::Get().GetSaveGameSystem();
     
     // If we have a save system and a valid name..
     if (SaveSystem)
     {
         // From SaveGameSystem.h in the Unreal source code base.
         FString saveGamePath = FString::Printf(TEXT("%s/SaveGames/*"), *FPaths::GameSavedDir());
 
         UE_LOG(TDLLog, Log, TEXT("Search path %s"), *saveGamePath);
 
         WIN32_FIND_DATA fd;
         HANDLE hFind = ::FindFirstFile(*saveGamePath, &fd);
         if (hFind != INVALID_HANDLE_VALUE) {
             do {
                 UE_LOG(TDLLog, Log, TEXT("  test name: %s"), fd.cFileName);
                 // Disallow empty names and . and .. and don't get all tied up in WCHAR issues.
                 if (fd.cFileName[0] == '\0'|| 
                     fd.cFileName[0] == '.' && fd.cFileName[1] == '\0' ||
                     fd.cFileName[0] == '.' && fd.cFileName[1] == '.' && fd.cFileName[2] == '\0')
                 { }
                 else if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 && fd.cFileName[0] != '.') {
                     ret.Add(FString(fd.cFileName));
                 }
             } while (::FindNextFile(hFind, &fd));
             ::FindClose(hFind);
         }
     }
 
     return ret;
 }


more ▼

answered Jul 12 '15 at 12:34 AM

avatar image

SND R Keene
988 31 120 113

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

Why not use a known name save file as master save file which contains names of all other save files?

  1. Create a save file "MASTER"

  2. Save your game with any name e.g "Savegame1"

  3. Add Savegame1 in "MASTER"'s file list

to load

1.Load Save file MASTER

2.Get the name of all save files from step 2 above

3.Load the save file you want from the list.

more ▼

answered Nov 20 '15 at 01:21 PM

avatar image

Commander Shepard
827 62 83 220

avatar image apoisonedgift Mar 21 '16 at 03:44 AM

The issue with this method is that if something happens to that master save, the user will lose the reference to all their other saves and most likely think all their save data has been lost. BPs really need a way to list all save games properly.

(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