I have been trying to load an asset from a pak file and after trying a number of different approaches cannot determine how to load an asset from it.
I can successfully mount a package and have managed to get a PakEntry by seaching the pakplatform (which also returns the PakFile it is located in) so I could read files manually ok.
However I cannot find any way to register the .uasset files in the pak with the assetregistry so that I can load them using something like StaticLoadObject.
An example of what I’m trying to do currently:
IPlatformFile& InnerPlatform = FPlatformFileManager::Get().GetPlatformFile();
FPakPlatformFile* PakPlatform = new FPakPlatformFile();
PakPlatform->Initialize(&InnerPlatform, TEXT(""));
FPlatformFileManager::Get().SetPlatformFile(*PakPlatform);
const FString pakFilename = TEXT("C:/.../Content/new.pak");
FString mountPoint(*FPaths::EngineContentDir());
if(PakPlatform->Mount(*pakFilename, 0, *mountPoint))
{ }
// RESULT - succeeds
// search for a file from the pak
FPakFile *assetPakFile = nullptr;
const FPakEntry *assetFile = PakPlatform->FindFileInPakFiles(*(mountPoint + TEXT("/mymesh.uasset")), &assetPakFile);
// RESULT - assetFile & assetPakFile both valid
// enumerate available static meshes
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(AssetRegistryConstants::ModuleName);
IAssetRegistry ®istry = AssetRegistryModule.Get();
registry.GetAssetsByClass("StaticMesh", assets, true);
// RESULT - no static meshes from the pak are visible
UStaticMesh* obj = Cast<UStaticMesh>(StaticLoadObject(UStaticMesh::StaticClass(), nullptr, *(mountPoint + TEXT("mymesh.mymesh"))));
// RESULT - obj is nullptr
As I say I have tried many different techniques and trawled much of the code and still failed miserably, this must be a relatively common process though as I assume it’s the way that DLC is handled?
Any suggestions greatly appreciated, I have scanned through multiple related forum posts and none of them seem to explain fully how this is done.