# Mounting pak files at runtime

**URL:** <https://forums.unrealengine.com/t/mounting-pak-files-at-runtime/298822>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [November 12, 2014, 12:48pm UTC](https://forums.unrealengine.com/t/mounting-pak-files-at-runtime/298822 "2014-11-12T12:48:52Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_7d5185b7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7d5185b7](https://forums.unrealengine.com/u/anonymous_user_7d5185b7)\
**Post date:** [November 12, 2014, 12:48pm UTC](https://forums.unrealengine.com/t/mounting-pak-files-at-runtime/298822/1 "2014-11-12T12:48:52Z")

</div>

I am trying to make content (static meshes) available after my application is shipped. The plan was to

1. add the dynamic content to the editor
2. cook and pack it into a .pak file
3. provide the .pak file on an http server
4. download the pak with the shipped client
5. mount the pak file and instantiate the content

1-4 are easy, but I could not get 5 done. I’m aware of [this post][1], but I don’t need any streaming, and I need to store the pak files at the client for offline availability.

For now, I tried the following (error checks omitted):

```
IPlatformFile& InnerPlatform = FPlatformFileManager::Get().GetPlatformFile();
FPakPlatformFile* PakPlatform = new FPakPlatformFile();

PakPlatform->Initialize(&InnerPlatform, TEXT(""));

FPlatformFileManager::Get().SetPlatformFile(*PakPlatform);

PakPlatform->Mount(Text("ABS_PATH_TO_PAK_FILE"), 0, *FPaths::EngineContentDir());

// trying to load the mesh
UStaticMesh* obj = Cast<UStaticMesh>(StaticLoadObject(UStaticMesh::StaticClass(), nullptr, TEXT("/Engine/PAK_INNER_DIR")));

```

I am not sure if the “PAK\_INNER\_DIR” (this is obviously a placeholder) is incorrect, or if I just understood something wrong with mounting paks.

Any suggestions?

[Stream an asset from the internet - Blueprint - Epic Developer Community Forums](https://answers.unrealengine.com/questions/109485/stream-an-asset-from-the-internet.html)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7d5185b7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7d5185b7](https://forums.unrealengine.com/u/anonymous_user_7d5185b7)\
**Post date:** [November 13, 2014, 9:57am UTC](https://forums.unrealengine.com/t/mounting-pak-files-at-runtime/298822/2 "2014-11-13T09:57:19Z")

</div>

Ok, now it works with Windows, but not with Android. There should not be much difference, right?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_958c07e8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_958c07e8](https://forums.unrealengine.com/u/anonymous_user_958c07e8)\
**Post date:** [March 17, 2015, 5:24pm UTC](https://forums.unrealengine.com/t/mounting-pak-files-at-runtime/298822/3 "2015-03-17T17:24:20Z")

</div>

Could u share the code you are using to do that please ?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a86f3523](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a86f3523](https://forums.unrealengine.com/u/anonymous_user_a86f3523)\
**Post date:** [June 29, 2015, 10:07pm UTC](https://forums.unrealengine.com/t/mounting-pak-files-at-runtime/298822/4 "2015-06-29T22:07:45Z")

</div>

What did you change to make it work with Windows?  
Can you show the complete program? I have a similar problem.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f41d4cf9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f41d4cf9](https://forums.unrealengine.com/u/anonymous_user_f41d4cf9)\
**Post date:** [July 13, 2015, 1:36pm UTC](https://forums.unrealengine.com/t/mounting-pak-files-at-runtime/298822/5 "2015-07-13T13:36:44Z")

</div>

same problem I have, Could u share the solution?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a08c0bf2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a08c0bf2](https://forums.unrealengine.com/u/anonymous_user_a08c0bf2)\
**Post date:** [October 27, 2015, 6:15pm UTC](https://forums.unrealengine.com/t/mounting-pak-files-at-runtime/298822/6 "2015-10-27T18:15:44Z")

</div>

Hey Everyone,

I’m not quite sure what you’re trying to do when you ‘mount the pak file and instantiate the content’, as that isn’t too clear to me. If you could explain this step further, I can dig deeper into our documentation and test this for you. With that being said, I’ve gathered a few AnswerHub posts and Documentation links that I feel may be helpful to what you’re trying to achieve:

- [Mounting .pak files at runtime][1]
- [Loading map from pak at runtime][2]
- [FPakFile Documentation][3]
- [Patch and DLC Support][4]

Thanks!

[Mounting pak files at runtime - World Creation - Epic Developer Community Forums](https://answers.unrealengine.com/questions/194148/mounting-pak-files-at-runtime-1.html)  
[2]: [Loading Map from Pak at Runtime - Programming & Scripting - Epic Developer Community Forums](https://answers.unrealengine.com/questions/258386/loading-map-from-pak-at-runtime.html)  
[3]: [FPakFile | Unreal Engine Documentation](https://docs.unrealengine.com/latest/INT/API/Runtime/PakFile/FPakFile/index.html)  
[4]: [Patch and DLC support - Platform & Builds - Epic Developer Community Forums](https://answers.unrealengine.com/questions/206824/patch-and-dlc-support.html)

---

<div class="post-metadata">

**Author:** ![burak.io](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@burak.io](https://forums.unrealengine.com/u/burak.io)\
**Post date:** [September 2, 2016, 1:04pm UTC](https://forums.unrealengine.com/t/mounting-pak-files-at-runtime/298822/7 "2016-09-02T13:04:25Z")

</div>

Yeah, can you share the code? How did you manage to solve this?

---

<div class="post-metadata">

**Author:** ![Anonymous\_22f547d62f00bac65c2343d67ba1c173](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_22f547d62f00bac65c2343d67ba1c173](https://forums.unrealengine.com/u/Anonymous_22f547d62f00bac65c2343d67ba1c173)\
**Post date:** [November 5, 2016, 8:16am UTC](https://forums.unrealengine.com/t/mounting-pak-files-at-runtime/298822/8 "2016-11-05T08:16:14Z")

</div>

> **[xia.rar\_免费高速下载|百度网盘-分享无限制](http://pan.baidu.com/s/1o7T8LnG)**
>
> 百度网盘为您提供文件的网络备份、同步和分享服务。空间大、速度快、安全稳固，支持教育网加速，支持手机端。注册使用百度网盘即可享受免费存储空间

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e41d67951](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e41d67951](https://forums.unrealengine.com/u/anonymous_user_e41d67951)\
**Post date:** [April 4, 2017, 4:48pm UTC](https://forums.unrealengine.com/t/mounting-pak-files-at-runtime/298822/9 "2017-04-04T16:48:27Z")

</div>

@CodeFluegel: Were you able to get it done. Kindly let me know how you did it. I am facing Engine crash.

---

<div class="post-metadata">

**Author:** ![TheMainStark](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/themainstark/32/1120943_2.png) [@TheMainStark](https://forums.unrealengine.com/u/TheMainStark)\
**Post date:** [March 24, 2018, 10:35am UTC](https://forums.unrealengine.com/t/mounting-pak-files-at-runtime/298822/11 "2018-03-24T10:35:43Z")

</div>

If anyone could provide a blueprint C++ class for this that would be amazing!

---

<div class="post-metadata">

**Author:** ![Rumbleball](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rumbleball](https://forums.unrealengine.com/u/Rumbleball)\
**Post date:** [October 30, 2018, 6:12pm UTC](https://forums.unrealengine.com/t/mounting-pak-files-at-runtime/298822/12 "2018-10-30T18:12:33Z")

</div>

**!!DO NOT USE THE CODE FROM THREAD CREATOR!!**

The code modifies the PlatformFile-Chain, which causes issues.  
Doing so, we had issues with IFileManager::FindFilesRecursive which was now returning multiples of the same file (~6 times the same file in our case) (the issue appeared only in a packaged project).  
Might be there are other issues as well.

The below code is modified to first look for a PakPlatformFile already existing in the PlatformFile-Chain and take that if it exists. That solved our issue.

```
//Load and mount pak file
    if (pakPlatformFile == nullptr)
    {
        // Search for an existing pakPlatformFile
        IPlatformFile* existingPakPlatformFile = FPlatformFileManager::Get().FindPlatformFile(TEXT("PakFile"));

        if (existingPakPlatformFile)
        {
            pakPlatformFile = static_cast<FPakPlatformFile*>(existingPakPlatformFile);
            UE_LOG(LogTemp, Log, "Using existing PakPlatformFile");
        }
        else
        {
            // When mounting a .pak file, we need to store a references to the .pak file in the platform file system.
            // To do this, we need a FPakPlatformFile that allows us to mount our .pak and keeps the information about the package.
            pakPlatformFile = new FPakPlatformFile();
            // But we don't want the engine to lose information of other packages
            // (and what ever other stuff), thus get the current PlatformFile
            IPlatformFile& platformFile = FPlatformFileManager::Get().GetPlatformFile();
            // and place it into our new PlatformFile (PlatformFile-Chain).
            if (!pakPlatformFile->Initialize(&platformFile, TEXT("")))
            {
                UE_LOG(LogTemp, Fatal, "Failed to initialize PakPlatformFile");
            }
            // Not sure about this, see: https://answers.unrealengine.com/questions/574388/how-to-mount-a-pak-file-at-game-content-directory.html
            pakPlatformFile->InitializeNewAsyncIO();
            // Now give the new PlatformFile to the engine.
            FPlatformFileManager::Get().SetPlatformFile(*pakPlatformFile);

            UE_LOG(LogTemp, Log, "Using our own PakPlatformFile");
        }
    }
```

---

<div class="post-metadata">

**Author:** ![as3mbus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@as3mbus](https://forums.unrealengine.com/u/as3mbus)\
**Post date:** [January 24, 2024, 8:47am UTC](https://forums.unrealengine.com/t/mounting-pak-files-at-runtime/298822/13 "2024-01-24T08:47:12Z")

</div>

if someone stumbles onto this page, epic already provides a guide and example project for people to look into.

> **[Example Project: Loading Pak Files At Runtime | Tutorial](https://dev.epicgames.com/community/learning/tutorials/7Bj8/unreal-engine-example-project-loading-pak-files-at-runtime)**
>
> The PakDemo project demonstrates a standalone application created by an Unreal Engine Project that can load assets from a .pak file from the local files...
