# How to load assets from a pak file at runtime?

**URL:** <https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713>\
**Category:** Rendering\
**Tags:** dlc, unreal-engine, CPP, question\
**Created:** [December 17, 2015, 12:00pm UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713 "2015-12-17T12:00:57Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_60d883c4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_60d883c4](https://forums.unrealengine.com/u/anonymous_user_60d883c4)\
**Post date:** [December 17, 2015, 12:00pm UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/1 "2015-12-17T12:00:57Z")

</div>

Now I have a pak file, which contains some .uasset files. I want to load the .uasset files at runtime but the code doesn’t work right. The code is as below:

```
    IPlatformFile &PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
    FPakPlatformFile *PakPlatfromFile = new FPakPlatformFile;
    PakPlatfromFile->Initialize(&PlatformFile, TEXT(""));
    FPakFile PakFile(PakFileName, false);
    UE_LOG(LogDynamicStaticMeshActor, Log, TEXT("Init - IsPakFileValid:%d"), PakFile.IsValid());
    FString MountPoint(FPaths::EngineDir());
    int32 PakOrder = 0;
    if (!PakPlatfromFile->Mount(PakFileName, PakOrder, *MountPoint)) {
        UE_LOG(LogDynamicStaticMeshActor, Fatal, TEXT("Mount error"));
    }

    UObjectLibrary *ObjectLibrary = ConstructObject<UObjectLibrary>(UObjectLibrary::StaticClass());
    ObjectLibrary->UseWeakReferences(true);
    ObjectLibrary->AddToRoot();
    UE_LOG(LogDynamicStaticMeshActor, Log, TEXT("Before load asset"));
    ObjectLibrary->LoadAssetDataFromPath(MountPoint);
    if (ObjectLibrary->IsLibraryFullyLoaded()) {
        UE_LOG(LogDynamicStaticMeshActor, Log, TEXT("Fully loaded"));
        ObjectLibrary->LoadAssetsFromAssetData();
    }

    TArray<FAssetData> AssetDataList;
    int32 count = ObjectLibrary->GetAssetDataCount();
    UE_LOG(LogDynamicStaticMeshActor, Log, TEXT("count:%d"), count);

```

It seems the mount step is successful, but when it runs to ObjectLibrary-\>LoadAssetDataFromPath(MountPoint), it is not fully loaded belong to the log, and ObjectLibrary-\>GetAssetDataCount() returns zero.

Also I’ve tried other ways:

```
void ADynamicStaticMeshActor::Init(const TCHAR* PakFileName) {
    IPlatformFile &PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
    FPakPlatformFile PakPlatfromFile;
    PakPlatfromFile.Initialize(&PlatformFile, TEXT(""));
    FPakFile PakFile(PakFileName, false);
    UE_LOG(LogDynamicStaticMeshActor, Log, TEXT("Init - IsPakFileValid:%d"), PakFile.IsValid());
    FString MountPoint(TEXT("/Engine/Content/DLC/"));
    int32 PakOrder = 0;
    if (!PakPlatfromFile.Mount(PakFileName, PakOrder, *MountPoint)) {
        UE_LOG(LogDynamicStaticMeshActor, Fatal, TEXT("Mount error"));
    }

    TArray<FString> AssetFileNames;
    PakFile.FindFilesAtPath(AssetFileNames, *MountPoint);

    for (const FString &AssetName : AssetFileNames) {
        UE_LOG(LogDynamicStaticMeshActor, Log, TEXT("AssetName:%s"), *AssetName);
    }

    FString MaterialFilePath = MountPoint + TEXT("BR_DongChenMingHan_6.uasset");
    FString MaterialFileContent;
    FFileHelper::LoadFileToString(MaterialFileContent, *MaterialFilePath);
    UE_LOG(LogDynamicStaticMeshActor, Log, TEXT("Path:%s Content:%s"), *MaterialFilePath, *MaterialFileContent);

    UStaticMeshComponent *StaticMeshComponent = NewObject<UStaticMeshComponent>(this, TEXT("staticMeshCom"));
    FStreamableManager StreamableManager;
    FString AssetName(MaterialFilePath);
    FStringAssetReference AssetRef(AssetName);
    Cast<UMaterial>(StaticLoadObject(UMaterial::StaticClass(), nullptr, *AssetName));
    UObject *Object = StreamableManager.SynchronousLoad(AssetRef);
    UMaterial *Material = Cast<UMaterial>(Object);
}

```

it could not load the assset file BR\_DongChenMingHan\_6.uasset to string. So I’m not sure whether the mount step is successful? And when loading the asset using StaticLoadObject, It logs “can’t find object” and I am really confused about this log for the file path seems correct.  
The related log is as below:

```
LogDynamicStaticMeshActor: Init - IsPakFileValid:1
LogDynamicStaticMeshActor: Path:/Engine/Content/DLC/BR_DongChenMingHan_6.uasset Content:
LogLinker:Warning: Can't find file '/Engine/Content/DLC/BR_DongChenMingHan_6'
LogLinker:Warning: Can't find file '/Engine/Content/DLC/BR_DongChenMingHan_6'
LogUObjectGlobals:Warning: Failed to find object 'Material /Engine/Content/DLC/BR_DongChenMingHan_6.uasset'
LogDynamicStaticMeshActor: Before load Object
LogLinker:Warning: Can't find file '/Engine/Content/DLC/BR_DongChenMingHan_6'
LogUObjectGlobals:Warning: Failed to find object 'Object /Engine/Content/DLC/BR_DongChenMingHan_6.uasset'
LogStreamableManager: Failed attempt to load /Engine/Content/DLC/BR_DongChenMingHan_6.uasset

```

It’s very kind of u if anyone teach me the right resolution, for I’ve spent several days on this problem.

---

<div class="post-metadata">

**Author:** ![Schopi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Schopi](https://forums.unrealengine.com/u/Schopi)\
**Post date:** [December 17, 2015, 1:29pm UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/2 "2015-12-17T13:29:44Z")

</div>

I don’t understand why you use LoadFileToString. Why do you want to load a uasset into a string ? Maybe this is because I don’t use FStreamableManager but I would build this way :

```
FString MaterialFilePath = MountPoint + TEXT("BR_DongChenMingHan_6.BR_DongChenMingHan_6"); // the reference to the object in the engine, not the path of the file
UMaterial *Material = Cast<UMaterial>(StaticLoadObject(UMaterial::StaticClass(), NULL, *MaterialFilePath));

```

Also I don’t understand why this line don’t return any log :

```
UE_LOG(LogDynamicStaticMeshActor, Log, TEXT("AssetName:%s"), *AssetName);

```

Are you sure that you have uasset files into your pak file ?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_60d883c4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_60d883c4](https://forums.unrealengine.com/u/anonymous_user_60d883c4)\
**Post date:** [December 18, 2015, 2:37am UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/3 "2015-12-18T02:37:29Z")

</div>

I mistakenly thought the mount is just like the shell command mount, which maps the files under a path. But I still don’t understand what “the reference to the object in the engine” exactly means, would u mind give me some documents? After all, it still logs can’t find file ‘/Engine/Content/DLC/BR\_DongChenMingHan\_6’ even though I change the path to MountPoint + TEXT(“BR\_DongChenMingHan\_6.BR\_DongChenMingHan\_6”)

that UE\_LOG(LogDynamicStaticMeshActor, Log, TEXT(“AssetName:%s”), \*AssetName) doesn’t log may be because that PakFile.setMountPoint is not called. And I am quite sure the pak file contains BR\_DongChenMingHan\_6.uasset for I’ve extracted it to a folder using UnrealPak.exe

---

<div class="post-metadata">

**Author:** ![Schopi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Schopi](https://forums.unrealengine.com/u/Schopi)\
**Post date:** [December 18, 2015, 10:00am UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/4 "2015-12-18T10:00:57Z")

</div>

The reference to the object is what you get in the editor when you right click on an asset and pick “copy reference”. You can see that even if this is a path, the extension is not ‘.uasset’. It looks like ‘/Game/Content/DLC/BR\_DongChenMingHan\_6.BR\_DongChenMingHan\_6’ and Game/ is replaced by /Engine when the asset is mounted. So yes the mount kind of maps the files under a path but not exactly I guess.

Anyway you already have a problem before if the \*AssetName is not logged during your loop. I don’t see any difference between your code and mine so if you are absolutely sure that you have your asset into your pak file I don’t know what your problem is.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_60d883c4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_60d883c4](https://forums.unrealengine.com/u/anonymous_user_60d883c4)\
**Post date:** [December 24, 2015, 10:00am UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/5 "2015-12-24T10:00:18Z")

</div>

Thank you for your reply and now I can load assets under the game folder at runtime, but still cannot load assets from a pak file. I’m absolutely sure that the pak file contains the assets. Or would u mind show me the right code, for I’ve spent tens of hours on this problem but still have no answer.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_762950041](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_762950041](https://forums.unrealengine.com/u/anonymous_user_762950041)\
**Post date:** [January 3, 2016, 11:25am UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/6 "2016-01-03T11:25:56Z")

</div>

这个问题，我也在研究，好像PAK文件mount后，必须要注册，见引擎源文件的UObjectBase::AddObject接口，加我的QQ：1346362278

---

<div class="post-metadata">

**Author:** ![Schopi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Schopi](https://forums.unrealengine.com/u/Schopi)\
**Post date:** [January 4, 2016, 11:47am UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/7 "2016-01-04T11:47:37Z")

</div>

No, sorry, I can’t. I don’t have the legal right to do this.

---

<div class="post-metadata">

**Author:** ![NelsonBilber](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NelsonBilber](https://forums.unrealengine.com/u/NelsonBilber)\
**Post date:** [March 2, 2016, 7:56pm UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/8 "2016-03-02T19:56:49Z")

</div>

When I put the \*.pak file on default folder “./Content\Paks” and application init for the first time it load the asset and I can use it.  
But if I drag and drop another \*.pak file to the same folder during runtime, the application don’t load the content to memory. Even if I code an explicit method to do it.

It’s possible to replicate the behaviour of loading a \*.pak file content at init() method during runtime ?

Regards,  
Nelson

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_bd1f080f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_bd1f080f](https://forums.unrealengine.com/u/anonymous_user_bd1f080f)\
**Post date:** [May 5, 2016, 2:02am UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/9 "2016-05-05T02:02:22Z")

</div>

我是在异步加载资源的时候遇到问题，FStreamableManager 的RequestAsyncLoad方法，日志输出LogLinker:Warning: The file ‘…/…/…/LoadTest/Content/Content/ArchVis/Textures/T\_Wood\_S.uasset’ contains unrecognizable data, check that it is of the expected type.  
是不是我pak文件生成有问题，你的pak文件是怎么生成的，我用的ProjectLauncher来做的基于一个release的dlc

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_189f1cd5](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_189f1cd5](https://forums.unrealengine.com/u/anonymous_user_189f1cd5)\
**Post date:** [July 17, 2016, 12:41pm UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/10 "2016-07-17T12:41:25Z")

</div>

我现在也在做从pak文件中加载\*.uasset，可以mount到指定的目录，但是最后加载\*.uasset失败，大家能给点建议吗？

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_189f1cd5](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_189f1cd5](https://forums.unrealengine.com/u/anonymous_user_189f1cd5)\
**Post date:** [July 20, 2016, 3:32am UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/11 "2016-07-20T03:32:43Z")

</div>

![99179-qq截图20160720110054.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/8/a/d8ab3ab92cb4a27dd548b1025c6765c4fc8c945b.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0f0b33f3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0f0b33f3](https://forums.unrealengine.com/u/anonymous_user_0f0b33f3)\
**Post date:** [September 30, 2016, 7:07am UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/12 "2016-09-30T07:07:25Z")

</div>

Hi~

I have just solved this problem.

The key is the asset’s path.

Remeber,When you are using the StaticLoadObject method.

You path should be Path1/Path2/Pathxx/AssetName.AssetName

Instead of AssetName.uasset or AssetName.umap…

try to change the path and let me know if you solve this problem

Here is my code,and it worked correctly!!

 ![109095-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/1/d/f1dd16e159df8ac9e3a8fdf10f921e9c0ea1efd1.png)

---

<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 3, 2016, 11:52am UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/13 "2016-11-03T11:52:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![panha](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@panha](https://forums.unrealengine.com/u/panha)\
**Post date:** [February 20, 2017, 1:55pm UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/14 "2017-02-20T13:55:20Z")

</div>

Guys please help!

> **[Mounting pak files(successful) but android load uasset fail](https://forums.unrealengine.com/questions/562601/mounting-pak-files-android-load-fail.html)**
>
> Hi guys, I try to mount pak file at running time and then load the static mesh use, it works on both editor and standalone version of window. However it will not work on android( I did package the pak file using android cooked assets) this is the...

---

<div class="post-metadata">

**Author:** ![BigBen1992](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BigBen1992](https://forums.unrealengine.com/u/BigBen1992)\
**Post date:** [July 15, 2017, 12:27pm UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/15 "2017-07-15T12:27:14Z")

</div>

我也是这个问题！！！！！！

---

<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:** [February 28, 2018, 4:23pm UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/16 "2018-02-28T16:23:03Z")

</div>

Copy&Paste

```
    void AAssetLoad::LoadPakFile()
	{
		IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
		FPakPlatformFile* PakPlatformFile = new FPakPlatformFile(); 
		PakPlatformFile->Initialize(&PlatformFile, TEXT(""));
		FPlatformFileManager::Get().SetPlatformFile(*PakPlatformFile);

		const FString PakFilename = FPaths::GameContentDir() + TEXT("Data/OutPak1.pak");
		FPakFile PakFile(*PakFilename, false);
		
		const FString MountPoint(FPaths::EngineContentDir());
		PakFile.SetMountPoint(*MountPoint);

		if (PakPlatformFile->Mount(*PakFilename, 0, *MountPoint))
		{
			UE_LOG(LogClass, Log, TEXT("Mount Success"));
			TArray<FString> FileList;

			PakFile.FindFilesAtPath(FileList, *PakFile.GetMountPoint(), true, false, true);
			FStreamableManager StreamableManager;
			
			// Static load object
			FString AssetName = FileList[0];
			FString AssetShortName = FPackageName::GetShortName(AssetName);
			FString LeftStr;
			FString RightStr;
			AssetShortName.Split(TEXT("."), &LeftStr, &RightStr);
			AssetName = TEXT("/Engine/") + LeftStr + TEXT(".") + LeftStr;
			FStringAssetReference Reference = AssetName;

			UObject* LoadObject = StreamableManager.SynchronousLoad(Reference);
			if (LoadObject != nullptr)
			{
				UE_LOG(LogClass, Log, TEXT("Object load Success..."));
			}
			else
			{
				UE_LOG(LogClass, Error, TEXT("Can't load asset..."));
			}
		}
		else
		{
			UE_LOG(LogClass, Error, TEXT("Mount failed"));
		}
	}
```

---

<div class="post-metadata">

**Author:** ![UnrealLF](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UnrealLF](https://forums.unrealengine.com/u/UnrealLF)\
**Post date:** [June 8, 2018, 7:33am UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/17 "2018-06-08T07:33:02Z")

</div>

Print “Can’t load asset…”

---

<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:** [June 8, 2018, 1:13pm UTC](https://forums.unrealengine.com/t/how-to-load-assets-from-a-pak-file-at-runtime/341713/18 "2018-06-08T13:13:52Z")

</div>

Its been some month since I did that stuff. If I remember right this code did not work for me directly either. You also must make sure you mountpoint and stuff is correct. He sets the mountpoint manually. Try to omit that. The mountpoint is in the pakfile and should get read automatically. Try debug the code and see where it goes wrong.

Another thing: This is very basic code just to get you started. The code creates a new FPakPlatformfFile every time. That is ■■■■■■■■. You only need one. I made a singleton class that creates that file uppon creation and caches it.

I wanted to provide the Plugin I made via Marketplace, but as I’m again working on other stuff I haven’t got to test it toroughly.
