FFileHelper::LoadFileToString and FPaths::FileExists cannot find file

Hi!

Due to lacking documentation on how package interaction works with these functions, i’m at a complete loss at what i should try next.

What i’m trying to achieve: I have a file in this path “C:/ue4/GameName/Content/text/test.txt”, i want to read that file into a string. I’ve also added “text” to the list of Additional Non-Asset directories to Package, and To Copy.

What i’ve tried: FFileHelper::LoadFileToString does not change the input string when given the exact above path, both manually and using FPaths::GameDir/GameContentDir etc. Same goes for FPaths::FileExists which agrees that the file, which is clearly there for me, does in fact not exists to UE4 when playing from Viewport nor standalone. This is after compiling and pressing Build.

What should i try next?

Instead of FPaths::FileExists, use IPlatformFile.FileExists() to check if file exists and read contents:

example:

    FString fileContent = "";
    FString filePath = FString("C:/ue4/GameName/Content/text/text.txt");
    IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
        
    if (PlatformFile.FileExists(*filePath))
    {
         UE_LOG(LogTemp, Warning, TEXT("File found");
         FFileHelper::LoadFileToString(fileContent, *filePath);
    }
    else
    {
         UE_LOG(LogTemp, Warning, TEXT("File not found");
    }

Something along those lines should work; I tested similar code (writing instead of reading), and it worked.

Reference:
https://wiki.unrealengine.com/File_Management,_Create_Folders,_Delete_Files,_and_More

You don’t have the correct number of brackets around your UE_LOG… should be

UE_LOG(LogTemp, Warning, TEXT(“File found”));

and

UE_LOG(LogTemp, Warning, TEXT(“File not found”));