Loading assets from a pak file

Hey ,

Thanks for your answer :slight_smile:

Small consolation to know i’m not the only hungry cat around^^

If Tom (http://www.tomlooman.com/add-mod-sup...engine-4-game/) is right, then it is already supposed to be very easy.

The official patcking doc (Updating Unreal Engine Projects With Patches After Release | Unreal Engine 5.2 Documentation) is not clear about where to put the pak file.
The last two notes confuse me between the /content/Pak and Releases/ directories.

note 1:
The patching process creates a pak file in [ProjectName]\Saved\StagedBuilds[PlatformName][ProjectName]\Content\Paks. This pak file is the patch that should be distributed to users. For example, on Windows, you would create an installer to copy that pak file into the user’s [ProjectName]\Releases[VersionNumber][PlatformName] folder, next to the original content pak file.

note 2:
Copy the pak file from ShooterGame\Releases\1.0\WindowsNoEditor to ShooterGame\Saved\StagedBuilds\WindowsNoEditor\ShooterGame\Content\Paks

My english is not very good but i understand the following:
note 1: ā€œcopy from Content/Paks to Releases/ā€
note 2: ā€œcopy from Releases/ to Content/Paksā€

The good news is they don’t speak about any code modification so whatever the directory used, i guess it’s supposed to be automatic.

Content/Paks seemed the natural candidate as it already contains the main pak file and works very well with it.
But you never know unless you try.
I didn’t test the Releases/ dir yet, so i’ll have to.

I’ll go on with my tests while i’ve some energy left for this and will of course let everyone know here if i make some (lucky) progress.

Otherwise i’ll end up doing what you did: put this aside and wait for some solid support from epic.

Cheers !

Hey,

Just a small update, i did a few tests this week end and (as expected but i had to try) it lead nowhere.

So i’m still stuck, same place as everybody else.

Having no stable place to start from, the number of things to test is exponentially large :frowning:

Hopefully we’ll get some help from epic on this matter.

Cheers !

I had code for umap’s working on 4.10 using :
FCoreDelegates::OnMountPak // and
IFileManager::Get().FindFilesRecursive(mapFiles, FPaths::GameContentDir(), TEXT(".umap"), true, false);

But it’s no longer working :(. I did a bit of debugging and diffing source files, but haven’t found the regression yet. I’ll take another pass at this later, but need to get other things done for the moment.

Well I found a hacky workaround…



PakPlatform = reinterpret_cast<FPakPlatformFile*>(const_cast<void*>(FCoreDelegates::OnMountPak.GetDelegateInstance()->GetRawUserObject()));
auto gameDir = FPaths::GameDir();
FPaths::MakeStandardFilename(gameDir);
PakPlatform->Mount(*mapPath, 4, *gameDir);


The problem is that the mount path set internally does not work for me. This allows me to explicitly set it to gameDir which does work. I would like to find a better way to get the FPakPlatformFile* since this method is very fragile, but it does work.

Hope this helps someone, and that this isn’t necessary in the future.

I’m still trying to get things sorted.
It will be a huge help for people like me if any of you can explain the Mount Point thing with actual paths.

Just ignore whether those assets are cooked or not.

For example here are the given pathes
My Create file c:\create.txt
Asset file1 c:\asset\book1.uasset
Asset file2 c:\Program Files\EpicGames\4.12\Engine\Content\book2.uasset
Asset file3 c:\412\MyProject\Content\book3.uasset | (In game content path)
Engine path c:\Program Files\EpicGames\4.12\Engine

PackedGamePath d:\412\MyProject
PackedEnginePath d:\412\Engine
TargetSavedPakFolder d:\412\MyProject\Paks
PackedGameContentFolder d:\412\MyProject\Content

What would be the Command to Generate Pak File?
c:\Program Files\EpicGames\4.12\Engine\Binaries\Win64\UnrealPak.exe <OutPak.pak> -create=c:\create.txt -Dest=???

With the ā€œOld Methodā€ what would the mount point and AssetRef be?

What about ā€œOnMountPak Methodā€?

no need of dest field for UnrealPak . it will force u to find mounting oath in hard way.

just remove it and create the pak file normally.

then put your mount point as :

ā€œā€¦/…/…/Game/ā€

for
Asset file3 c:\412\MyProject\Content\book3.uasset | (In game content path)

that will work .

if your asset is in :

c:\412\MyProject\Content\myfolder\book3.uasset | (In game content path)

then mount point would be:

ā€œā€¦/…/…/Game/myfolderā€

Guys please help me… on android mounting pak file and load the asset!

Hello guys,
I can mount my .pak file and


Result = PakPlatformFile->Mount(*File, NewOrder, *FPaths::GameContentDir());

return true in editor and standalone launch but i haven’t access to files. (In this case i used not cooked assets)
The problem is very bad when i create my shipping version of project and cooked assets when i try to load an assets project crash! Again that funcrtion return true for mounting .pak file.

Looking into this too at the moment.

I was able to get something using a second project with the same name.

!!!THIS IS STILL WORK IN PROGRESS AND THE RESULTS ARE NOT AS EXPECTED!!! See below.
EDIT:

Solved my issues, see EDIT below.

  1. From your main project go to File->PackageProject->Windows->WindowsPlatform
  2. Chose MainPackageDir
  3. Make a second project that has the EXACT SAME PROJECT NAME but in a different directory
  4. Add some materials to Content/Mods
  5. Package the second project the same way as the first
  6. Chose a SecondPackageDir
  7. Go to SecondPackageDir/WindowsNoEditor/PROJECTNAME/Content/Pak
  8. Rename the .pak to ProjectName_Mod.pak (or Whatever.pak) as at the moment it is the same filename as the main project and that will not work.
  9. Copy the ProjectName_Mod.pak to MainProjectDir/WindowsNoEditor/PROJECTNAME/Content/Pak
  10. Start .exe of the main project

But nothing happend? Right, how could it? The assets are only mounted correctly at the moment, not used in the game.

So how to access the stuff:
Create a C++ BlueprintFunctionLibrary and add the following function.



    /**
     *  Get (and load) all assets from a folder relative to GameDir/Content that match the class.
     *
     *    @param assetClass   Class of the assets to look for
     *    @param path            Path is relative to GameDir/Content e.g. "/somepath". NOTE: "" or "/" WILL NOT WORK!!!
     *    @param assets        OUT: The assets found
     */
    UFUNCTION(BlueprintPure, Category = "Utility", meta  = (DeterminesOutputType = "assetClass", DynamicOutputParam = "assets"))
        static void GetAllAssetsInDirectoryRecursive(const TSubclassOf<UObject> assetClass, const FString path, TArray<UObject*>& assets);
{
    UObjectLibrary* objectLibrary = UObjectLibrary::CreateLibrary(assetClass.Get(), false, true);
    objectLibrary->LoadAssetsFromPath(*(FString(TEXT("/Game")) / path));
    objectLibrary->GetObjects(assets);
    // As the library is a UObject it should be picked up by the GarbageCollector now *pray*
}


  1. Add the function in your code where you want to access the assets and package the main project again.
  2. Run the .exe of the main project

The C++ function works flawlessly within the main project.

My Issues:
I’m currently only trying with textures and materials from the mod
-Textures seem to work without issue
-Materials are bugged at this time. Just a simple red material from the mod shows up as a high specular glitch that changes color depending on time and view angle
-This only works when restarting the game, not at runtime.

And as we package the mod project the normal way, we also include engine content that we don’t want. This might also lead to my material issue. The mod.pak is ~100MB for a simple texture and material.

EDIT:
-To fix the material issue, the projects must have the same rendering settings. Materials are broken when loaded from a pak file - Rendering - Unreal Engine Forums
-It is possible to exclude the engine content when packaging by using chunks. This way the custom content is one or multiple chunks (separate .pak files). Cooking Content and Creating Chunks in Unreal Engine | Unreal Engine Documentation
Then move only the correct chunkX.pak over to the main project. It should also be possible to make manual cooking/packaging code that ignores the engine stuff but did not look in that yet.

Have you tried using the Asset Manager?

Can somebody explain how to use FCoreDelegates::OnMountPak? Is see that you need to call .Execute on it, and when the engine is bound to it, it will load the specified file. But as always, the signature parameters are not documented.


    // delegate type for prompting the pak system to mount a new pak
    DECLARE_DELEGATE_RetVal_ThreeParams(bool, FOnMountPak, const FString&, uint32, IPlatformFile::FDirectoryVisitor*);

FString&: should be the path to the .pak
uint32: Goes to PakOrder, see below. Seems to be the order in which pak files are read. Highest number = loaded first.
IPlatformFile::FDirectoryVisitor*: what is this needed for and what to give it? Need to create a new FDirectoryVisitor or do we need to get on already existing from somewhere?

If OnMountPak is bound by FPakPlatformFile, it delegates to


    /**
     * Handler for device delegate to prompt us to load a new pak.    
     */
    bool HandleMountPakDelegate(const FString& PakFilePath, uint32 PakOrder, IPlatformFile::FDirectoryVisitor* Visitor);

Where is the documentation …

Not yet. Had a look at it, but it seems more to be for assets in the main project and loading them in when needed. Not loading .pak at runtime and getting references to the stuff.

What you had in mind with the Asset Manager exactly? Packaging out? Loading in? Both?

Also it seems you need to work with primary assets and bundles to make use of the Asset Manager. I’m looking into this for modding and it should be possible to just create a material and package that out, load it in the other project. This must work at runtime, as we are going for mod support and multiplayer (ya know, the ā€œI want to connect to server but I miss the modsā€ issue).

I’ve just found a very interesting answer on Answer Hub, which actually helped me a lot! Here it is:

Where is iit?

solution to this is ChunkDownloader.

Assign your game content to have different chunkIds and then they will be compiled into different paks and you can send and download these into a game as dlc!
Also this is how Valorant does it, go into val content folder and you see: