How to point 'saved' directory on PC to %localappdata%

Hi,

What is best way to change where the ‘saved’ directory is saved out so that it goes to %localappdata% for all configs not just SHIPPING?

Thanks,

Simon

Hi there,

In what context are you trying to save?

Using the following you can get a file path to local app data on windows:

FString FileName = "MySaveGame"
FString Path = FPlatformMisc::GetEnvironmentVariable(TEXT("LOCALAPPDATA"));
Path /= FApp::GetProjectName();
Path /= FileName;

If you are using UGameplayStatics::SaveGameToSlot you can use the results as the SlotName argument to save to that location.

I hope that helps,

Louis

Hi Louis,

Perfect!

Thank you.

Simon

Hi Louis,

No. Looking to have the “saved” directory to be saved in %localappdata% for DEV & TEST along with SHIPPING.

Not had much look finding in the code where to change.

Thanks,

Simon

Sorry about the confusion there. You most likely will need to make changes to the engine to achieve this. The area you will want to look into is the Paths.h file. Specifically FPaths::ProjectSavedDir and the functions called within it. There are a few paths it can take to get the project saved directory depending on defined Macros, Platform processes, etc. The easiest and quickest option to achieve this is adding the -userdir command line argument when launching the editor/game. e.g in a shortcut’s Target:

"C:\<EnginePath>\UnrealEditor.exe" "C:\<ProjectPath>\MyProject.uproject" -userdir="C:\CustomDirectory"I tried looking into another option without modifying the engine by defining the UE_SAVED_DIR_OVERRIDE macro. However i believe due to FPaths::ShouldSaveToUserDir() this would still require engine source changes.

Here is a link to a forum post that discusses this topic, they’re trying to achieve the opposite but there is some useful information regardless.

Cheers,

Louis

Hi,

This is confusing for sure.

Lets start with a shipping build what gets changed for that config so points to %localappdata%?

I don’t mind changing the engine for this so if you can tell me what to change would be much appreciated.

Thanks,

Simon

Hi, sorry for the confusion again.

The function you will want to modify for this would be FPaths::ShouldSaveToUserDir():

bool FPaths::ShouldSaveToUserDir()
{
	static bool bShouldSaveToUserDir =
		FApp::IsInstalled()
		|| FParse::Param(FCommandLine::Get(), TEXT("SaveToUserDir"))
		|| FPlatformProcess::ShouldSaveToUserDir()
		|| !CustomUserDirArgument().IsEmpty();
		
	return bShouldSaveToUserDir;
}

Specifically the call to FApp::IsInstalled() which has a check “#if UE_BUILD_SHIPPING” inside. This point is being reached from FPaths::ProjectUserDir() line 443 which is checking whether to return the project directory or the user directory. When instructed to use the user directory (unless it has been overridden) it will use a file path to localappdata.

If you want to modify the engine, this is a great place to start, Otherwise you can utilize the command line argument “-userdir” which might be easier if you just need a fast workaround.

Cheers,

Louis