Packaging non-asset files to Content/Paks/mygame.pak and open this files via c++

Hello! I want to pack non-asset files to PAK archive in Content folder of my game. For example: test.txt. I do it this way: In Project→Packaging→Additional Non-Asset Directories to Package I add folder “Custom”. This folder is located in the Content folder. This folder contains test.txt. I’m not sure if I’m packaging the file correctly. Because I can’t access it through the C++ code:

FString FileContent;
FString FilePath = TEXT(“/Game/Custom/test.txt”);

if (FFileHelper::LoadFileToString(FileContent, *FilePath)) ….

I tried to set folder: FString FilePath = TEXT(“Custom/test.txt”);

The file did not open. I searched for the file in the log after packing the project, but I couldn’t find it. However, when I opened the pak file via hex editor, the file name and the strings it contains are present in pak. Why can’t I open my text file?

2025-11-05_10-06-48

Try to use FPaths::ProjectContentDir() in your code.

For example:

FString FileContent; // Get the content directory root (works in editor and packaged build)
FString ContentDir = FPaths::ProjectContentDir(); // Append your file's relative path
FString FilePath = ContentDir + TEXT("Custom/test.txt");

if (FFileHelper::LoadFileToString(FileContent, *FilePath))
{
// Success! FileContent now contains the text.
UE_LOG(LogTemp, Warning, TEXT("File Read Success: %s"), *FileContent);
}
else
{
// Failure
UE_LOG(LogTemp, Error, TEXT("Failed to read file at path: %s"), *FilePath);
}

2 Likes

Yes It works, thanks! FPaths::Combine(ContentDir, TEXT(“Custom/test.txt”)) is better than strings append))

1 Like