Mounting pak files at runtime

Hi guys, Im using this plug in to mount pak file at runtime - GitHub - moritz-wundke/AsyncPackageStreamer: Simple plugin giving you the ability to load PAK files from the local FS or a remote one.

The plugin compiles with no issues and can be used on UE4.7.2, what I’m trying to do is stream a local pak file, this is my code:

UTestSingletonClass* dataInstance = Cast<UTestSingletonClass>(GEngine->GameSingleton);
FAssetStreamer *obj = new FAssetStreamer();
obj->Initialize(&dataInstance->AssetLoader);
obj->CurrentMode = EAssetStreamingMode::Type::Local;
FString pakFile = TEXT("Out.Pak");
FString args = TEXT("-pakdir=");
args += FPaths::GameContentDir() + TEXT("/Paks");
obj->StreamPackage(pakFile, this, EAssetStreamingMode::Type::Local,*args);

but the engine crashes due to a null pointer exception on this class FPakPlatformFile::FindAllPakFiles, Im not sure if I’m using the plug in correctly or not, does anybody have used such plug in before ??

thanks in advance.

I’m suffering a same problem. Is there any people that have used AsyncPackageStreamer plugin?

The way I solved this problem, assuming the pak file was setup correctly, was to load a local pak file with the following code:

if (FCoreDelegates::OnMountPak.IsBound()) {
     FCoreDelegates::OnMountPak.Execute(PakPath, 4); //Number should be 0-4; specifies search order
}

Where PakPath is an FString that points to the location of your pak file. Once you load in the pak file you can access the maps and other assets from within the pak file the same way you would if they had been packaged with your game.

Hi, I’m tring to load a PAK file for my game(in case, I have used the TopDown project)
But, I have failed to load a PAK file.

  1. I made a “MyPlayer” blueprint class from Character BP at “Content/TopDown/Blueprints/MyPlayer.uasset”
  2. Made a PAK file for my new asset using UnrealPak.exe.
    ->E:\GitHub\UnrealEngine\Engine\Binaries\Win64\UnrealPak.exe F:\BAK\MyProject\Content\Paks\Output.pak -create=F:\BAK\MyProject\Saved\PakList_pakchunk0-Android_ETC1.txt

Content of “PakList_pakchunk0-Android_ETC1.txt” is below
“F:\BAK\MyProject\Content\TopDown\Blueprints\CHAR\MyPlayer.uasset” “…....\Engine\Content\MyPlayer.uasset” -compress

  1. Run UnrealFileServer.exe

  2. My client code loads that Pak file.
    FString PakFile = FPaths::GameContentDir() + FString(TEXT(“Paks/”)) + “Output”;
    FString Args = TEXT(“-pakdir=”);
    Args += FPaths::GameContentDir() + TEXT(“Paks/”);
    ExpansionAssetStreamer->StreamPackage(PakFile, nullptr, EAssetStreamingMode::Local, *Args);

  3. Crashed while load the PAK file in StreamPackage()

  4. Error Message is
    “LoadPackageAsync failed to begin to load a package because the supplied package name was neither a valid long package name nor a filename of a map within a content folder: ‘’”

What is a problem of my code?

Me too ,Who can help us

did anybody have any success?

did anybody have any success?

mfish,which engine version you were using?

Pak file generation :

Cooked vs un-Cooked content

cooking means you need process your assets and optimize them for your target platform, uncooked assets are not optimized and intended to work only
for development under UE4 editor.

if you are working on a development build you create the pak files using *.uasset files from the editor using unrealPak.exe as follows:

Command line argument -
[path+executable] [location of desired
pak+name.pak] –create=[location of pak
list file.txt] -compress

Example :

d:/ue4/Engine/Binaries/Win64/UnrealPak.exe
//someSharedAssetFolder/SomeProject/Pak/SomeAwesome.pak
-create=d:/temp/filesListToProcess.txt –compress

On the other hand if you want to use pak files on stand alone builds you need to cook the contents for your target platform for example Windows / Linux / iOS / PS, etc.
Cooked folder is normally found at:
\Cooked\WindowsNoEditor\YourProjectName\Content\Assets\

if the folder is empty or does not exists is because you havent “cooked” the contents for the target platform, and you can do it within the editor, just go to
File menu and click “Cook contents for [Target Platform]”

NOTE: To avoid confussions you should name you pak files according to the target:

• If the list is generated from editor.uassets, then the pak file should end with _Editor.pak

• If the list is generated from cooked file assets, then the pak file should end with _Standalone.pak.

Editor or “uncooked” content wont work with Stand Alone / Distribution / Shipping builds

Using the plugIn

  1. Create a folder called “Plugins” at the root level of your game

  2. Copy the contents of AsyncPackageStreamer into it, the file structure should look like this:
    • YourGame\Plugins\AsyncPackageStreamer

  3. Verify if it’s correctly installed by opening UE4 Editor go to Window Menu → PlugIns → Project (Async Package Streamer should be listed there) also when opening the editor
    for the first time it should start compiling the plugIn

  4. Add a reference to YourProjectName.Build.cs (located at the root level of the solution) to include the plugin Headers into the compilation process:

    PublicDependencyModuleNames.AddRange(new string { “Core”, “CoreUObject”, “Engine”, “InputCore”, “UMG”,
    “Slate”, “SlateCore”, “HTTP”, “Json”, “JsonUtilities”, “MoviePlayer”,
    “PakFile”, “Sockets”,“StreamingFile”, “NetworkFile”,
    “AsyncPackageStreamer”,…

  5. Create a class somewhere a Test widget will be enough for testing and include the AsyncPakage streamer header file:

    include “AssetStreamer.h”

    include “TestWidget.generated.h”

    /**

    • Sample class for testing button click callbacks and service callbaks
      */
      UCLASS()
      class VSPEC_APP_API UTestWidget : public IAssetStreamerListener // implement AsyncAssetStreamer Interface
      {
      GENERATED_BODY()

    public:

     UTestWidget(const FObjectInitializer& ObjectInitializer);
    
     void OnAssetStreamComplete();            // AsyncPakage Streamer abstract Method
     void OnPrepareAssetStreaming(const TArray<FStringAssetReference>& StreamedAssets); // AsyncPakage Streamer abstract Method
     
     UFUNCTION(BlueprintCallable, Category = "Click Handlers")
     void OnLoadPakClick();
    

    private:
    UPROPERTY(EditAnywhere, Category = “Dynamic Loaded Content”)
    TArray MyStreamedAssets;

     FStreamableManager streamableManager;   // Engine StreamManager Instance
     ......
    
  6. Implement IAssetStreamer methods

    void UTestWidget::OnLoadPakClick()
    {
    FAssetStreamer *assetStreamer = new FAssetStreamer();
    assetStreamer->Initialize(&this->streamableManager);
    assetStreamer->CurrentMode = EAssetStreamingMode::Type::Local;
    FString pakFile = “C:\MyAwesomePak”;
    assetStreamer->StreamPackage(pakFile, this, EAssetStreamingMode::Type::Local, TEXT(“”));

    }

    void UTestWidget::OnPrepareAssetStreaming(const TArray& StreamedAssets)
    {
    MyStreamedAssets = StreamedAssets; // Prepare a local reference of the assets to be streamed
    }

    void UTestWidget::OnAssetStreamComplete()
    {
    for (int32 i = 0; i < MyStreamedAssets.Num(); ++i)
    {
    check(Cast(MyStreamedAssets[i].ResolveObject()) != nullptr); // you have to cast to the exact type Texture2d, StaticMesh, etc…
    }
    }

which engine version you were using ?
I was having crush on 4.10 and 4. 11 .
Although that was my own implementation. I will try out yours one today.
thanks for the tutorial.

Same issue here. Try to use asset from server by this method. Hope someone do a video or something about how to use asset from server by PAK file method.

Hi Zetarus, the reason for the crash is highly likely because the pak file you are using is not cooked for Android, to do such thing just open UE4 Editor then go to File->Cook Content for Android and when is done create the pak file using the uassets located in:

YourProjectName\Saved\Cooked\AndroidXXX\

Remember if you create a pak file just using directly the uncooked content located in YourProjectName\Content it wont work on standalone builds, pak files created in that way just work when launching the game within the Editor and its intended for debugging purposes.

That should be it.

Hugo.

I been using this approach since UE4.7 now I’m using UE4.10 and still works as intended

hugomj_ca and mfish,
we appreciate your time and effort to answer all these amateur questions.
But most of us having no luck.
for reference, Can u guys post a proper pak file which is working fine on your side?
Using that pak we at least we can figure out where the problems lies on our side.
On cooking process
or
in Code.

Thanks.

This solution has been working for me since 4.6 and still works today. The assets do need to be cooked prior to packing as detailed by hugomj_ca. This works in standalone builds only due to the cooked/uncooked issue in the IDE. In my implementation I used libcurl to download the pak files from a server and then loaded them, all during runtime, with the method above.

Sure, attached you can find 2 pak files, one for Editor (uncooked) and one for stand alone builds (Cooked for Windows (PC)), the contents are a bunch of textures – Flag textures to be precise –

Sample Pak

Note: Is always better to work using the full source code of the engine, not the binary build, in that way you can see the full stack trace and figure out issues as they come in a more verbose way.

Hugo.

I’m getting the same exception:

Exception thrown: read access violation.
LowLevelFile was 0xFFFFFFFFFFFFFFFF.
If there is a handler for this exception, the program may be safely continued.
>	UE4Editor-PakFile.dll!FPakPlatformFile::FindAllPakFiles(IPlatformFile * LowLevelFile, const TArray<FString,FDefaultAllocator> & PakFolders, TArray<FString,FDefaultAllocator> & OutPakFiles) Line 588	C++
 	UE4Editor-PakFile.dll!FPakPlatformFile::Initialize(IPlatformFile * Inner, const wchar_t * CmdLine) Line 671	C++
 	UE4Editor-AsyncPackageStreamer.dll!FAssetStreamer::UseLocal(const wchar_t * CmdLine) Line 151	C++
 	UE4Editor-AsyncPackageStreamer.dll!FAssetStreamer::StreamPackage(const FString & PakFileName, IAssetStreamerListener * AssetStreamerListener, EAssetStreamingMode::Type DesiredMode, const wchar_t * CmdLine) Line 65	C++
 	UE4Editor-DynamicAssetLoad.dll!UTestWidget::OnLoadPakClick() Line 63	C++
 	UE4Editor-DynamicAssetLoad.dll!UTestWidget::Pak_HttpRequestComplete(TSharedPtr<IHttpRequest,0> HttpRequest, TSharedPtr<IHttpResponse,1> HttpResponse, bool bSucceeded) Line 52	C++

I’m following the guidelines described by hugomj_ca about the PAK file creation (PAK from WindowsNoEditor cooked uassets):

If anyone’s interested, they can take a look at my code.

same. hugomj_ca’s sample pak did not help.
always crashing at " LowLevelFile".

ue4.10.3

i am felling that either the address have someting to do or the code work only on older version

is it 4.10.3 ?

i have found the solution of crash problem. a variable was wrongly initiaintialized. because of wrong value LowLevelFile value assignment operation always was skipped . thats why it was always null and always was crashing.
now i have to check if pak file successfully get mounted.
if it works now then i will post the fix until then dont waste your time to make the plugin work. it will always crash.