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";