Why does FGenericPlatformProcess::GetCurrentWorkingDirectory( ) always return an empty string?

Hi all…
I have a C++ class where I need to try and determine the location of the currently running app. I need to build a path off this. But for some reason, this always returns and empty string.

I’ve tried calling both as a static class

FString path = FGenericPlatformProcess::GetCurrentWorkingDirectory( );

And creating an instance

FGenericPlatformProcess proc;
FString path = proc.GetCurrentWorkingDirectory( );

Both of which just return an empty string… Is there a different function that I should be using to try and get the currently running UE app location?

Thanks

Hi there, you should use the FPaths class, which provides various useful methods for dealing with paths. Specifically, you can use FPaths::ProjectDir() to get the directory of the project or FPaths::ProjectContentDir() to get the content directory of the project.

Getting the Project Directory

#include "Misc/Paths.h"

FString ProjectDirectory = FPaths::ProjectDir();
UE_LOG(LogTemp, Log, TEXT("Project Directory: %s"), *ProjectDirectory);

Getting the Content Directory

#include "Misc/Paths.h"

FString ContentDirectory = FPaths::ProjectContentDir();
UE_LOG(LogTemp, Log, TEXT("Content Directory: %s"), *ContentDirectory);

Hope this helps.

1 Like

Hi Spud…

Thank you for your help… Oddly, I’m actually using FPaths in my project already, not sure why I didn’t think about trying to see if it would support my needs.

Guess I couldn’t see the forest through the trees. :smiley:

1 Like

No problem at all mate, glad I could guide you through the fog :sweat_smile:

Actually… not sure if this is going to work either… It works fine when you play in the PIE, but when I try running a package build, it’s almost as if the path got baked into the exe because the path seems to be completely wrong.

Even if I have a project build deploy with this type of folder structure.

c:\MyGame\MyGame.exe

When I do a print string on Paths::ProjectDir() I see something like this.

../../../MyGame

Which looks like it’s somehow trying to pick up the original path… SO… I searched through all the functions on this class and found

LaunchDir()

That did exactly what I needed it to do…
Basically I am home rolling my own Config file… I need to know where to go find it… For now, I just wanted it to sit in the exact same location as the game.exe…