Hello guys,
I need to load at runtime a set of asset that will be downloaded from a distant server (a kind of DLC), and I’m stuck.
My strategy is to use the Editor for creating a package with my assets for a chosen platform, than use the .pak file in a second project (where it will be loaded at runtime).
**1. It is the right way to do ? **
For the moment, I can only mount the .pak file, and get the list of files in the pack:
IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
FPakPlatformFile* PakPlatformFile = **new** FPakPlatformFile();
PakPlatformFile->Initialize(&PlatformFile, TEXT(""));
FPlatformFileManager::Get().SetPlatformFile(*PakPlatformFile);
**const** FString PakFilename = FPaths::ProjectContentDir() + TEXT("PakFiles/FirstDLC-MacNoEditor.pak");
**const** FString MountPoint = FPaths::EngineContentDir();
FPakFile pak_file{PakPlatformFile->GetLowerLevel(), *PakFilename, **false**};
pak_file.SetMountPoint(*MountPoint);
PakPlatformFile->Mount(*PakFilename, 0, *MountPoint)
2. How to load theses assets into memory ?
From what I saw, the most recent solution is to use the AssetManager object:
→ Create a primary asset object in the project, and link it with all asset that I want to export, with the same bundle tag for each asset.
→ Export the package
→ Try to import the primary asset, what goes load all secondary assets linked.
UAssetManager &asset_manager = UAssetManager::Get();
FPrimaryAssetId package_id = asset_manager.GetPrimaryAssetIdForPackage(package_name);
FPrimaryAssetId primary_asset{"DLCObjects:FirstPack"};
FAssetBundleData bundle_data;
bundle_data.AddBundleAsset("AllTextures", soft_path);
asset_manager.RecursivelyExpandBundleData(bundle_data);
asset_manager.AddDynamicAsset(primary_asset, FStringAssetReference{}, bundle_data)
/*
TArray<FName> bundle_names;
bundle_names.Add(FName{"AllTextures"});
//Then call *asset_manager.GetPrimaryAssetObject(primary_asset);
*/*
But I never successfully get my UObject. I’m missing something ?
In an other hand, I find there is an AssetRegistry.bin file in the .pak file. I saw that when we mount a package, the file is loaded in memory and get references to the assets, but here too a got nothing from my file. Is this method still working ?
I also tried some methods with ObjectLibrary, but if I well understood the Asset Manager doc, this is an ancient method and the Asset manager is preferred.
Which method should I prefer today ?