Packaged Game Paths, Obtain Directories Based on Executable Location

Overview

Author: Rama (talk)

Dear Community,

Here is how you get access to various parts of the directory structure of a Packaged game!

You do not need to use ConverRelativePathToFull while testing WITH_EDITOR builds, though it will still work correctly.

But it is essential to include in packaged builds!

Below are the directories that get returned for each of several different UE4 C++ FPath:: functions!

You can use pretty much any one of these to then create your own directory structure all inside of wherever your game's packaged binary is running from.

How It Works

All the other paths are found by using the BaseDir, where the exe is running from.

This is determined at runtime, so if the entire project is moved, all the paths below will still work correctly!

InstallDir/WindowsNoEditor/GameName/Binaries/Win64

//InstallDir/WindowsNoEditor/GameName/Binaries/Win64
FString ThePath = FString(FPlatformProcess::BaseDir());

InstallDir/WindowsNoEditor/ (or other OS)

Please note this will differ based on the OS you are packaging the game for :)

//InstallDir/WindowsNoEditor/
FString ThePath = FPaths::ConvertRelativePathToFull(FPaths::RootDir());

InstallDir/WindowsNoEditor/GameName

//InstallDir/WindowsNoEditor/GameName
FString ThePath = FPaths::ConvertRelativePathToFull(FPaths::GameDir());

InstallDir/WindowsNoEditor/GameName/Content

//InstallDir/WindowsNoEditor/GameName/Content
FString ThePath = FPaths::ConvertRelativePathToFull(FPaths::GameContentDir());

InstallDir/WindowsNoEditor/GameName/Saved

//InstallDir/WindowsNoEditor/GameName/Saved
FString ThePath = FPaths::ConvertRelativePathToFull(FPaths::GameSavedDir());

InstallDir/WindowsNoEditor/GameName/Saved/Logs

//InstallDir/WindowsNoEditor/GameName/Saved/Logs
FString ThePath = FPaths::ConvertRelativePathToFull(FPaths::GameLogDir());

Sandbox File Path

When run the program in WindowsNoEditor mode. All file I/O will be saved to a Sandbox folder.

In this case, the real path on the disk is wrapped by ConvertToSandboxPath, defined in IPlatformFileSandboxWrapper.cpp. This ConvertToSandboxPath is different from FPaths::ConvertToSandboxPath.

To get the real filename on the disk. You need to call GetFilenameOnDisk to get the real filename. Notice: The file must has been written to the disk. Otherwise the GetFilenameOnDisk will only return the directory name.

IFileManager& FileManager = IFileManager::Get();
FString DiskFilename = FileManager.GetFilenameOnDisk(*FullFilename);

qiuwch (talk)

Dynamic Relocation of Project

The above code I am sharing with you will work even if you change the location of your packaged game after packaging!

Try it!

I added many many subdirectories between my InstallDir and WindowsNoEditor and it still worked perfectly!

So even if the end user moves everything starting with WindowsNoEditor around, the above code will still generate the correct and updated directory structure!

Conclusion

Now you know how to create your own directory structures relative to the installation directory of your packaged game!

Enjoy!

Rama (talk)