Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Loading Map from Pak at Runtime

I'm trying to add content dynamically to my game during runtime and am running into some strange behavior. I've bundled up all the assets for a particular map into a separate pak file which then gets mounted using the following code:

     FPakPlatformFile* PakPlatform = new FPakPlatformFile();
     PakPlatform->Initialize(&PlatformFile, TEXT(""));

     UE_LOG(LogTemp, Log, TEXT("Mounting pak %s"), *PakPath);
     if (!PakPlatform->Mount(*PakPath, 0, TEXT("../../../"))) {
         UE_LOG(LogTemp, Error, TEXT("Failed to mount %s"), *PakPath);
 else {
     UE_LOG(LogTemp, Log, TEXT("Serializing asset data for %s"), *PakFilename);
     FArrayReader SerializedAssetData;
     int32 DashPosition = PakFilename.Find(TEXT("-"), ESearchCase::CaseSensitive, ESearchDir::FromEnd);
     if (DashPosition != -1)
         PakFilename = PakFilename.Left(DashPosition);
         FString AssetRegistryName = PakFilename + TEXT("-AssetRegistry.bin");
         UE_LOG(LogTemp, Log, TEXT("AssetRegistryName %s"), *AssetRegistryName);
         if (FFileHelper::LoadFileToArray(SerializedAssetData, *(FPaths::GameDir() / AssetRegistryName)))
             // serialize the data with the memory reader (will convert FStrings to FNames, etc)
             UE_LOG(LogTemp, Warning, TEXT("%s could not be found"), *AssetRegistryName);

This code seems to work when my pak file is already present when the game is started. The problem I'm having is when the pak file is added to the game while it's running (whether by downloading it from a server or manually copying the file). The map still loads but the textures are all messed up and there is an infinite loop of log messages which state:

 The file '.../.../.../Game/Content/Maps/NextMap.umap' contains unrecognizable data, check that is is of the expected type.

The level I'm trying to load has a few sublevels, which are the ones listed in the warnings. I know there is nothing wrong with the pak file since the map will load just fine if I restart the game leaving the pak file there when it starts up.

So my question: What am I missing? What is Unreal doing under-the-hood upon startup in regards to pak files that I'm not replicating properly when I try to manually load the pak file?

Product Version: UE 4.8
more ▼

asked Jul 15 '15 at 05:21 PM in C++ Programming

avatar image

31 1 2 4

avatar image FoorKang Sep 08 '16 at 09:13 AM

Hello! From the UnrealEngine community, How to dynamically load the specified content in the PAK (as in a blueprint, material, and the name of the image from the PAK). Can you give me a demo code? My email address is 3217142879@qq.com

Thanks to you!

avatar image 咔咔_虚 Oct 25 '16 at 03:34 AM

I have the same program. Do you have a solution now . 我也是同样的问题,cooked 后的asset打包后,在进行加载,材质的贴图不正确,就跟上图一样,现在不知道怎么弄了!

(comments are locked)
10|2000 characters needed characters left

3 answers: sort voted first

Well, it turns out I was trying too hard. I replaced all the above code with the following:

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

And now it works. Turns out there are several useful FCoreDelegates which can help with basic things. Hope this helps someone else.

more ▼

answered Jul 16 '15 at 02:55 PM

avatar image

31 1 2 4

avatar image w279287350 Jul 18 '15 at 09:42 AM

I'm trying to dynamically add content

and use UnrealPak.exe to packing pak, but no find AssetRegistry.bin file

How to get the AssetRegistry.bin?

Can you give me demo, or implementation of steps?

avatar image mfish Jul 30 '15 at 01:37 PM

These instructions for how I make the pak file is assuming windows. The process is similar on OSX:

You’ll first need to cook the assets. I find that the easiest way to do that is to simply add the content into a new project and create a packaged build: -1st go to File->Packaging->Packaging Preferences and make sure “For Distribution” is checked. -2nd go to File->Packaging->Windows->64-bit to create the packaged build.

During that process Unreal will cook the content for you and by default they’ll be in %YourProjectDirectory%\Saved\Cooked\WindowsNoEditor There will also be a txt file that was generated in: "C:\Users\yourusername\AppData\Roaming\Unreal Engine\AutomationTool\Logs\C+Program+Files+Epic+Games+4.8\PakList_ProjectName-WindowsNoEditor.txt" This file is what Unreal is using to create the pak file and will save you time to make yours. You can go through that file and delete all the lines of files you don’t need for your Content (everything that points to engine, config, and starter content for example). Then you can run the following command to create the pak file: “C:\Program Files\Epic Games\4.8\Engine\Binaries\Win64\UnrealPak.exe” C:\location\of\output\Content.pak -create=C:\path\to\modifed\PakList_ProjectName–WindowsNoEditor.txt

If you want to make a compressed pak file then in the paklist txt file you need to add "-compress" to the end of each line (or use the compress setting before cooking the content).

avatar image w279287350 Jul 31 '15 at 03:43 AM

I encountered a strange problem, Static mesh texture at runtime exception in win64. alt text Thanks for you

IPlatformFile& InnerPlatform = FPlatformFileManager::Get().GetPlatformFile(); FPakPlatformFile* PakPlatform = new FPakPlatformFile(); PakPlatform->Initialize(&InnerPlatform, TEXT("")); FPlatformFileManager::Get().SetPlatformFile(*PakPlatform);

 UE_LOG(LogGame, Warning, TEXT("IndexExpansionContent"));


//GFilePathBase UE4Game FString InFeaturePackPath = TEXT("Content/RestrictedAssets/Pak/MyAssetPak.pak"); #else FString InFeaturePackPath = FPaths::GameContentDir() + TEXT("RestrictedAssets/Pak/MyAssetPak.pak"); #endif if (FCoreDelegates::OnMountPak.IsBound()) { //PakPlatform->Mount(*InFeaturePackPath, 4, *FPaths::GameContentDir()); FCoreDelegates::OnMountPak.Execute(InFeaturePackPath, 4); } GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *FPaths::GameContentDir()); GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *InFeaturePackPath); UE_LOG(LogGame, Warning, TEXT("OnMountPak"));

 UStaticMesh*  objX = Cast<UStaticMesh>(StaticLoadObject(UStaticMesh::StaticClass(), nullptr, TEXT("StaticMesh'/Game/RestrictedAssets/Fbx/baijian5.baijian5'")));
 UE_LOG(LogGame, Warning, TEXT("StaticLoadObject objX"));
 AStaticMeshActor* actor = GetWorld()->SpawnActor<AStaticMeshActor>(FVector::ZeroVector, FRotator::ZeroRotator);
 actor->GetStaticMeshComponent()->Mobility = EComponentMobility::Movable;

20150731.png (227.1 kB)
avatar image mfish Jul 31 '15 at 12:16 PM

You should comment out those first 3 lines (IPlatformFile...) as they may be doing something undesirable (Unreal does a lot under the hood that I don't fully understand, even when looking under the hood). I had similar texture issues when I asked the original question. I'm not seeing anything obviously wrong with the way you're spawning the mesh. I can take another look at my own code to see if I'm doing anything else differently.

avatar image w279287350 Aug 01 '15 at 02:32 AM

comment out those first 3 lines (IPlatformFile...)
but FCoreDelegates::OnMountPak.IsBound() == false at edit mode Do I still need to modify other place?

Can you give me a demo code?
My email address is w279287350@gmail.com

Thanks to you!

avatar image mfish Aug 03 '15 at 04:23 PM

I guess I forgot to mention that I'm always testing in a standalone build and not within the editor. My project relies on everything being loaded dynamically at runtime from pak files which are loaded on demand, which I couldn't get working from within the editor.

avatar image Muzaheed Mar 29 '16 at 04:28 PM

@w27... were you able to solve the problem of " FCoreDelegates::OnMountPak.IsBound() == false at edit mode " ? same on my side. always false.

avatar image helloliu Jul 30 '16 at 09:21 AM

hello,Can you explain the specific role of this function it?"FCoreDelegates::OnMountPak.Execute(PakPath, 0, nullptr)",Thanks for you!

avatar image RichardB Jan 29 '16 at 05:25 PM

Hi, I'm having similar problems, I've got the pak file loading, I've got the OpenLevel parsing the Init Code again (cannot debug step into that code with as debugGame does not bind the OnMountPak) but the original level is still showing and the World name is the same. How did you get the newly loaded level to display? Thanks.

avatar image FoorKang Sep 08 '16 at 09:15 AM

Hello! From the UnrealEngine community, How to dynamically load the specified content in the PAK (as in a blueprint, material, and the name of the image from the PAK). Can you give me a demo code? My email address is 3217142879@qq.com

Thanks to you!

avatar image masmil1988 Nov 24 '17 at 10:39 AM

What if FCoreDelegates::OnMountPak.IsBound() returns false? I'm trying with PIE, standalone and packaged versions, and always it returns false...

avatar image TestyRabbit May 03 '18 at 06:43 AM

@mfish I know it's been a few years but I'm trying to do this exact same thing. Whenever I mount a pak file with OnMountPak.Execute() and I try to use UGameplayStatics::OpenLevel() it tells me it can't resolve the map file. Did you experience this? How did you fix it? Ive been struggling with this for weeks now.

avatar image masmil1988 May 03 '18 at 07:56 AM

Sure, I've gone mad to solve this problem and, finally, I solved by "just" modifying a single character of the engine source code and recompiling it. In the file \Engine\Source\Runtime\PakFile\Private\IPlatformFilePak.cpp you have to modify the row #define EXCLUDE_NONPAK_UE_EXTENSIONS 1 and change that 1 to 0

So compile the engine (a custom engine, not the Epic's one) and try again. It requires some hours to download and compile the engine, but it's worth it. You may have other problems in the future which require an engine edit.

avatar image TestyRabbit May 03 '18 at 08:14 AM

You changed that one thing and you were able to load a map after mounting a pakfile with OnMountPak.Execute()?

avatar image masmil1988 May 03 '18 at 08:52 AM

Yes. This is my code:

bool ULevelsFunctionLibrary::MountPak(FString PakPath) {
if (FCoreDelegates::OnMountPak.IsBound()) {
return FCoreDelegates::OnMountPak.Execute(PakPath, 0, NULL);
return false;

before of that changing, the if check failed (and the Execute method too, if I called it in spite of the failed check). After that changing, the pak file is correctly mounted and I'm able to load the pak's maps.

avatar image TestyRabbit May 03 '18 at 06:42 PM

Okay, I'm going to try that now. Your code overall was basically this?

 bool ULevelsFunctionLibrary::MountPak(FString PakPath) {
     if (FCoreDelegates::OnMountPak.IsBound()) {
         if (FCoreDelegates::OnMountPak.Execute(PakPath, 0, NULL))
               UGameplayStatics::OpenLevel(GetWorld(), "map");
               return true;
     return false;
avatar image TestyRabbit May 03 '18 at 07:38 PM

this didnt work, when I got to OpenLevel it still gave me failed to resolve map.umap.

(comments are locked)
10|2000 characters needed characters left

I've got static mesh by loading pak file,and static mesh texture have black spot at runtime in win64. Could you give me some advices?Thanks.

more ▼

answered Sep 05 '16 at 06:29 AM

avatar image

1 1 4

avatar image Verilog Sep 08 '16 at 03:52 AM


avatar image FoorKang Sep 08 '16 at 09:15 AM

Hello! From the UnrealEngine community, How to dynamically load the specified content in the PAK (as in a blueprint, material, and the name of the image from the PAK). Can you give me a demo code? My email address is 3217142879@qq.com

Thanks to you!

avatar image FoorKang Sep 08 '16 at 09:16 AM


(comments are locked)
10|2000 characters needed characters left
more ▼

answered Feb 20 '17 at 01:55 PM

avatar image

23 6 13 9

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question