Hi, is there any way to check if any save file exists in the SaveGames folder? Not a particular save file name, but if ANY save file at all?
Thanks.
Enable the plugin BP FIle Utilities
And use these nodes where extension will be your .sav
(double check if directory and save extension work the same way for different platform on shipping ver)
Yep, you can check if any save file exists in the SaveGames
folder in Unreal Engine by using the file management functionalities provided by the engine.
Here’s a quick snippet:
#include "HAL/FileManager.h"
bool DoesSaveGameExist()
{
IFileManager& FileManager = IFileManager::Get();
// Construct the path to the SaveGames directory
FString SaveGamesDirectory = FPaths::ProjectSavedDir() + TEXT("/SaveGames/");
// Array to hold the names of found files
TArray<FString> FoundFiles;
// Search for any files in the SaveGames directory, excluding directories
FileManager.FindFiles(FoundFiles, *SaveGamesDirectory, *FString("*.*"));
// If FoundFiles is not empty, then there are save files present
return FoundFiles.Num() > 0;
}
This function will return true
if there are any files in the SaveGames
.
Thanks a lot.
How do I check that? Does “get project saved dir” not get the save files path, regardless of platform? What about the extension?
Well yes it supposed to but just a safe precaution
You will have to test manually.
Thanks a lot, guys.
I saw the array stores the save names in alphabetical order. Is there any way to get the last saved file by date time, or get them in chronological order?
You can add a variable that will store the date on each save file, so you will need to load each save file > get date >compare, and then sort your ui.
Or a workaround that will keep track of your last save id in your SaveSystem file, so that you only load one file to sort the ui. (but depending on your loading screen system, we most often have to load description, thumbnail of each file anyway)
Thanks. You mentioned thumbnail. Do you know of any tutorials on how to get that done? I’ve looked everywhere, can’t find anything on it, only how to take screenshots in editor which doesn’t help.
To take a screenshot ingame, you will need to use a RenderTarget.
Save Button > Spawn a Camera(with SceneCaptureComponet)> capture scene > export texture to disk with a correct id name.
Load Button > Loop each save file > Import Texture from disk that match save file id with screenshot name id > set Thumbnail.
Since it will create an additional file in .png in your save folder, double check your platform support that type of extension during Save, also your limit of files that be uploaded.
If you want to save the image inside a .sav itself, you will need c++ even though it possible also in BP but it will be very small dimension and very slow to load due to using large for each loop.
Thanks, but I wouldn’t know where to start. Tutorials online only show scene capture as a continuous rendering of what the camera sees.
You mean the export to disk node saves the image right when it’s called, or how does it work?
Create a SceneCaptureComponent in your actorBP.
Check out it detail panel and set it RenderTarget texture, you will need to modify other setting too.
You can manually CaptureScene with this node:
Then just do an export.
Do some trial and error, take your time, don’t always rely on yt
Check the output log, you need to add .png to your file name.
Did that too. No go.
the Output log says this:
LogScript: Error: Script Msg: Only EXR export is currently supported for PF_FloatRGBA and PF_A32B32G32R32F formats.
LogScript: Error: Script call stack:
/Game/FirstPerson/Blueprints/BP_FirstPersonCharacter.BP_FirstPersonCharacter_C.ExecuteUbergraph_BP_FirstPersonCharacter <—
/Game/FirstPerson/Blueprints/BP_FirstPersonCharacter.BP_FirstPersonCharacter_C.InpActEvt_Four_K2Node_InputKeyEvent_0
Edit:
If I change the extension to EXR it works, but I cannot use that as texture in game.
Never mind, I was being stupid. The file name was wrong in the widget I was trying to pull the image in.
It does work, but the image itself is transparent, on both formats. You can only see edge lines of the geometry.
Edit:
Never mind, again. I actually made it work. I just changed capture source option in scene capture component to RGB:
No UI, but it’s not really important for my case.
But now, I’m faced with a different dilema. Is it better to save these thumbnails into a .sav file and risk getting long load times when the game starts, because the images will add up to a lot of memory?
OR
Maybe I should just leave them on disk and pull them from there without the need to load an entire .sav file to get them?
Is there any downside to just leaving them on disk?
Thanks a lot for the help, btw.
Well putting an image into a .sav file is another story, you will have store them in Bytes which are even slower.
It should be fine saving them on a disk inside the Saved folder, if the image is like 64x64, i wouldnt be consern for memory.
In your Loading UI, when you will be loading a row, you need to use a FunctionTimer to load one row at a time (and not just ForEach everything at one go). Since reading from disk is slow around 2.0ms for an SSD.
In short, like you said, just load .sav like you would, then in the background slowly load your image thumbnail just like webpage do. (or like in Travelers Rest, in the shop when scrolling item)
Downside will be, user can go into their folder and modify but in most case that not really an issue.
The issue will be their size, since during steam cloud save, these need to be uploaded, when you exit Valheim for example, you can see a delay before the game close, it just saving everything before closing.
Thanks for the FunctionTimer tip.
Is that a steam requirement? Why can’t I just use the saved files on disk, without uploading to steam? My game is just single player, btw.
Well not really, i believe you can enable/disable that feature to be provided for users, but usually players expect a cloud save since they are not copying their save folder for each game when they install a new pc for example.
So basically, keep the save data as small as possible.
All good info, thanks a lot.