Announcement

Collapse
No announcement yet.

What is correct way to PAK files, load/mount them and load assets with AssetRegistry?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    What is correct way to PAK files, load/mount them and load assets with AssetRegistry?

    Hi guys, I want to do this:
    Create and package original game. Then I want to create additional PAK files with new meshes/sounds/animations and blueprints based on blueprint in original game. Original game should not know anything about additional meshes/animations/etc. So I need to create smart system with AssetRegistry in original game that scans all PAK files, load/mount them and with AssetRegistry scan those PAK files for all assets.

    What I did to achive my goal:
    I create and package successfully original game for target platform (windows standalone). Then in project I create additional content and cook them for target platform. I use UnrealPak.exe to create PAK files for additional content. I am able to load/mount PAK file in original game by placing PAK file in Paks folder and they load/mount at startup of the game (this sentence is based on the LOG file from original game, I dont know how to check if it is true or not). I am able to load/mount PAK file even with code by using FCoreDelegates::OnMountPak.Execute (this sentence is also based on the LOG file from original game). So loading/mounting PAK files should work well. But now where is the biggest issue. I want to use AssetRegistry to scan for all assets in all PAK files. I tried everything I came up with. I tried ScanPathsSynchronous method, GetAllAssets method. Only what happens is it loads assets from ORIGINAL GAME PAK FILE. It seems that AssetRegistry doesnt know anything about other PAK files. I tried to tell AssetRegistry where are those files with AddPath method and still doesnt work.

    So my example code what I tried is here:
    Code:
    • FString path1 = FPaths::ConvertRelativePathToFull(FString("../../../TestPaks/Content/Paks/test.pak"));
    • FString path2 = FPaths::ConvertRelativePathToFull(FString("../../../TestPaks/Content/Paks/testmaterial.pak"));
    • bool check1 = false;
    • bool check2 = false;
    • if (FCoreDelegates::OnMountPak.IsBound())
    • {
    • check1 = FCoreDelegates::OnMountPak.Execute(path1, 0, nullptr); //Number should be 0-4; specifies search order
    • check2 = FCoreDelegates::OnMountPak.Execute(path2, 0, nullptr); //Number should be 0-4; specifies search order
    • }
    • UE_LOG(LogTemp, Warning, TEXT("%s"), *path1);
    • UE_LOG(LogTemp, Warning, TEXT("%s"), *path2);
    • FString NewString1 = check1 ? "true" : "false";
    • FString NewString2 = check2 ? "true" : "false";
    • UE_LOG(LogTemp, Warning, TEXT("check 1 = %s"), *NewString1);
    • UE_LOG(LogTemp, Warning, TEXT("check 2 = %s"), *NewString2);
    • FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked(FName("AssetRegistry"));
    • IAssetRegistry& assetRegistry = AssetRegistryModule.Get();
    • TArray ContentPaths;
    • TArray data;
    • //assetRegistry.AddPath(path1);
    • FString contentRelativeDir = TEXT("/Game/Paks");
    • assetRegistry.AddPath(contentRelativeDir);
    • assetRegistry.ScanPathsSynchronous({ contentRelativeDir });
    • //assetRegistry.SearchAllAssets(true);
    • assetRegistry.GetAllAssets(data, false);
    • assetRegistry.GetAllCachedPaths(ContentPaths);
    • for (FString& data : ContentPaths)
    • {
    • UE_LOG(LogTemp, Warning, TEXT("GetAllCachedPaths: %s"), *data);
    • }
    • FString NewString = FString::FromInt(data.Num());
    • UE_LOG(LogTemp, Warning, TEXT("%s"), *NewString);
    • for (int32 i = 0; i < data.Num(); i++)
    • {
    • FString s = data[i].AssetName.ToString();
    • FString ss = data[i].AssetClass.ToString();
    • UE_LOG(LogTemp, Warning, TEXT("%s | %s"), *s, *ss);
    • }
    I tried a lot of versions of paths and nothing is working. I am in this mess around 2 weeks and I dont have any much more tips what to do and what will work. So how should this work properly??? I looked in forums here and stackoverflow and there are some solutions, but they dont work anymore.

    #2
    If what I remember wasn't wrong, this is a tricky thing in UE4. Only the one AssetRegistry.bin file under project folder would be loaded. If you want your project support additional pak files, one possible is generate AssetRegistry file for your additional pak file. And then change a little bit in UE4 source code, make it support loading all AssetRegistry files from Paks folder.

    Comment


      #3
      Originally posted by henryLiu View Post
      If what I remember wasn't wrong, this is a tricky thing in UE4. Only the one AssetRegistry.bin file under project folder would be loaded. If you want your project support additional pak files, one possible is generate AssetRegistry file for your additional pak file. And then change a little bit in UE4 source code, make it support loading all AssetRegistry files from Paks folder.
      Interesting never thought of that. Ans is there a better/different way to load assets from PAK files? I can load only assets from original PAK file, but I can not load assets from additional PAK files.

      Comment

      Working...
      X