How to Load Files from a Mounted PAK File?

RedVonix
Thu, 20 Jul 2023 20:31:25 +0000
Programming & Scripting

I’m able to successfully build a PAK file and inject it into our game - however I’m having issues being able to actually load anything from that PAK file. My code successfully finds all of the expected files in there, however when I go to actually load an asset from the PAK - that’s where I’m getting stuck. I’m not sure if I have the file paths wrong or what. Here’s my code so far for loading assets from the Pak file:

		TArray<FString> FileList;
		pakPlatformFile->GetPrunedFilenamesInPakFile(PakFileLocation, FileList);
		for(int i = 0; i < FileList.Num(); i++)
		{
			UE_LOG(LogTemp, Warning, TEXT("--- DEBUG PakFile Mount FILE FOUND: %s"), *FileList[i]);

			FString AssetName = FileList[i];
			FString FileName, FileExt;

			FSoftObjectPath StrNewAssetRef = AssetName;
			FStreamableManager AssetLoader;
			UObject* NewLoadedObject = AssetLoader.LoadSynchronous(StrNewAssetRef);
			if (NewLoadedObject)
			{
				// do something, cast to compatible type.
				UE_LOG(LogTemp, Warning, TEXT("--- DEBUG Successfully loaded file %s"), *NewLoadedObject->GetName());
			}
			else
			{
				UE_LOG(LogTemp, Warning, TEXT("--- DEBUG FAILED to load file at %s"), *AssetName);
			}
		}

There unfortunately isn’t a lot of documentation or information on this topic, so I’ve kind of pieced this together from what I have been able to find, which isn’t much.

My question is: How do you, at runtime, properly load assets from a mounted PAK file so they are available for use in a game?

2 posts - 2 participants