Need root directory for text file

I’m currently trying to load a text file from my games root directory, rather than having to give a full path to the function. My code at the moment is

	FString PathToLoad = "C:\\Users\\username\\Documents\\Unreal Projects\\GameTest\\TextFile.txt";
	if (!FPlatformFileManager::Get().GetPlatformFile().FileExists(*PathToLoad))
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("** Could not find file **"));
		return;
	}
	FFileHelper::LoadANSITextFileToStrings(*(projectDir), NULL, StringArray);

However, I want the path to already be at the root directory so I don’t have to use the full path name all the time. I have tried to use the FPath::GameDir() but can’t seem to get it working. Is there a way to do this so that I can use that to show where my project is and then grab the text file from there?

FString PathToLoad = FPaths::GameDir();
PathToLoad += "TextFile.txt";

what is GameDir() returning? it works great for me :slight_smile:

I must have bee doing something wrong somewhere stupid, checked again and made some other changes:

Here is my code anyway:

FString projectDir = FPaths::GameDir();
		projectDir += "Content/TextFile.txt";
		if (!FPlatformFileManager::Get().GetPlatformFile().FileExists(*projectDir))
		{
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("** Could not Find File **"));
			return;
		}
		FFileHelper::LoadANSITextFileToStrings(*(projectDir), NULL, StringArrat);

Which loads a file of strings on new lines into an array.

Let me note that probably FPaths::GameDir() doesn’t returns path with ending slash, thats why it might not worked