FPaths, FFileHelper and IFileManager after packaging

Hi there,

In order to allow the player to add custom simple dialogue chains to the game, I created a new plugin and added the following two blueprint nodes - one for finding all txt files inside a ‘Mods’ subfolder inside Content folder, and another to read these txt files:

.h

UCLASS()
class UModdingPlus : public UObject
{
	GENERATED_BODY()
	
public:

    UFUNCTION(BlueprintPure, Category = "ModdingPlus")
    static bool GetAllFilesFromFolder(TArray<FString>& Files, FString RootFolderFullPath, FString Ext);
    
    UFUNCTION(BlueprintPure, Category = "ModdingPlus", meta = (Keywords = "LoadTxt"))
    static bool LoadTxt(FString FileNameA, FString& SaveTextA);
};

.cpp

bool UModdingPlus::GetAllFilesFromFolder(TArray<FString>& Files, FString RootFolderFullPath, FString Ext)
 {
     if(RootFolderFullPath.Len() < 1) return false;
     
     // FPaths::NormalizeDirectoryName(RootFolderFullPath);
     
     //RootFolderFullPath = FPaths::ConvertRelativePathToFull(RootFolderFullPath);
     
     IFileManager& FileManager = IFileManager::Get();
     
     FString RelativePath = FPaths::GameContentDir();
     FString FullPath = FileManager.ConvertToAbsolutePathForExternalAppForRead(*RelativePath);
     
     if(Ext == "") 
     {
         Ext = "*.*";
     }
     else
     {
         Ext = (Ext.Left(1) == ".") ? "*" + Ext : "*." + Ext;
     }
     
     FString FinalPath = FullPath + "/" + RootFolderFullPath + "/" + Ext;
     FileManager.FindFiles(Files, *FinalPath, true, false);
     return true;                  
 }
 
 bool UModdingPlus::LoadTxt(FString FileNameA, FString& SaveTextA)
{
     return FFileHelper::LoadFileToString(SaveTextA, *(FPaths::GameContentDir() + FileNameA));
}

These blueprint nodes work perfectly for me when I play in editor - the txt files are found correctly inside the Mods folder, and their contents are converted to strings as expected.

However, both of these function return false as soon as I package the project (with the Mods folder manually copied into the built game’s Content folder).

Is there anything I could do? Or is it hard-coded that the packaged game cannot read external files?

Thank you so much in advance!

I have a same probleme. I’m too in UE4.18.
I see A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums But not work. How do ?

While I know this is an old question, I recently encountered and solved the same issue myself. BTW, this issue has been around since 4.10 at least; and is present all the way through 4.19.
My issue was that when I would package my project from within the Editor, any File Management functions for validating things like “FileExists” or “DirectoryExists” always returned false.

This behavior could not be seen when playing in Editor or StandAlone launched from the Editor.

The solution is to Package the project from the UE FrontEnd tool. All of my file management functions continue to work without issue then.

Important Note: The UE FrontEnd is a program (Binary) that you build from the Engine Source Code VS Solution. Once the FrontEnd program has been built from source (in Visual Studio for example), then you will find its EXE under the engine binaries like the UE-Editor.
If you’re using the public (non-source) engine that you downloaded via the Epic Launcher; the FrontEnd will not be available to you, even if your project is c++ based.

Do you have access to the commandline that is used when you package with unreal FrontEnd? Just came across that issue… Should be doable without unreal FrontEnd, just the commandline is wrong.

Edit: I entered a bug report.