Here’s my current very ugly and not clean code if you wondered (I’m talking to you person on the internet searching for UE4 pak loading documentation), Don’t use it as is, it logs everything, on screen and in the logs too.
Need to make FPakListEntry Struct public before running this, thus require to build the engine
// Load Pak
void AFireStarterGameMode::LoadPakFile(FString Path)
{
if (FCoreDelegates::OnMountPak.IsBound()) {
FCoreDelegates::OnMountPak.Execute(Path, 3, nullptr); //Number should be 0-4; specifies search order
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Pak should be loaded"));
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Is not Bound"));
}
IPlatformFile& InnerPlatformFile = FPlatformFileManager::Get().GetPlatformFile();
FPakPlatformFile* PakPlatformFile = new FPakPlatformFile();
PakPlatformFile->Initialize(&InnerPlatformFile, TEXT(""));
//PakPlatformFile->Mount(*PakToLoad, 0, *(Path)); // Not Original
TArray<FPakPlatformFile::FPakListEntry> MountedPaks;
PakPlatformFile->GetMountedPaks(MountedPaks);
UE_LOG(LogTemp, Warning, TEXT("Befroe Scan Loop"));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Before Scan Loop"));
//ignore first pak, because it is default game pak and we don't need iterate over it
for (int32 i = 0; i < MountedPaks.Num(); i++)
{
UE_LOG(LogTemp, Warning, TEXT("OnePack"));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("OnePack"));
const FPakPlatformFile::FPakListEntry& mountedPak = MountedPaks*;
const TMap<FString, FPakDirectory>& pakDirectoryMap = mountedPak.PakFile->GetIndex();
for (TMap<FString, FPakDirectory>::TConstIterator It(pakDirectoryMap); It; ++It)
{
FString Key = It.Key();
const FPakDirectory& Val = It.Value();
for (FPakDirectory::TConstIterator It2(Val); It2; ++It2)
{
FString Key2 = It2.Key();
FPakEntry* pakEntry = It2.Value();
//if (Key2.Contains(TEXT(".umap")))
//{
UE_LOG(LogTemp, Warning, TEXT("OneFile"));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("OneFile"));
//this is where you will get map name of course if your map have *.umap extension:)
Key2 = Key2;
UE_LOG(LogTemp, Warning, TEXT("File: %s"),*Key2);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red,TEXT("File: " + Key2));
//}
}
}
}
}