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!