How Load Asset From Pak File at Runtime?

This problem has been bothering me at Several weeks。

The StaticLoadObject() it aways is Null with return Value;

Who can help me ?

73451-x3vlk10l0`{h$j00{s_p}iu.png

void AMyFPS_Character::test_asynLoad()
{
	FPakPlatformFile *temp_pakFile = new FPakPlatformFile();
	IPlatformFile* temp_platform = &FPlatformFileManager::Get().GetPlatformFile();

	IPlatformFile *temp_platform1 = NULL;

	temp_pakFile->Initialize(temp_platform, TEXT(""));
	if (!FCoreDelegates::OnMountPak.IsBound())
	{
		return;
	}
	FString engine_dir(FPaths::GameContentDir().Append("PAK/")); // = FPaths::GameContentDir().Append("PAK/");
	FString mount_file = FPaths::GameContentDir().Append(TEXT("DLC/OutPak.pak"));
	
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, *engine_dir);
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, *mount_file);
	
	FPakFile pakFile(*mount_file, false);
	if (!pakFile.IsValid())
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("FPakFile IsInvalid"));
		return;
	}
	pakFile.SetMountPoint(*engine_dir);

	if (!temp_pakFile->Mount(*mount_file, 0, *engine_dir))
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("Mount Failed"));
		return;
	}

	FStringAssetReference itemRef("/Game/Content/PAK/2_2.2_2");
	TSet<FString> FileList; 
	pakFile.FindFilesAtPath(FileList, *pakFile.GetMountPoint(), true, false, true);
	for (auto item : FileList)
	{
		if (item.EndsWith(FPackageName::GetAssetPackageExtension()) ||
			item.EndsWith(FPackageName::GetMapPackageExtension()))
		{
			GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Cyan, FString::Printf(TEXT("PakFile Assert: %s "), *item));
		}
	}
	FStreamableManager *streamableMgr = new FStreamableManager();
	auto temp_matrial_test1 = streamableMgr->SynchronousLoad(itemRef);
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, FString::Printf(TEXT("Try Convert Object to UMaterial : %s "), temp_matrial_test1 != nullptr ? TEXT("True") : TEXT("False")));
	
	streamableMgr->RequestAsyncLoad(itemRef, FStreamableDelegate::CreateLambda([&]()
	{
		auto temp_matrial_test = StaticLoadObject(UMaterial::StaticClass(), NULL, TEXT("/Game/Content/PAK/2_2.2_2"));
		GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString::Printf(TEXT("Try Convert Object to UMaterial : %s "), temp_matrial_test != nullptr ? TEXT("True") : TEXT("False")));
	}));
}

你解决了吗?我也在研究类似的问题

/Game/ 就是对应的…/…/…/游戏名字/content/ 目录 也就是从编辑Game目录的目录结构 推荐加载pak到GameContent 目录
那么 通过UnrealPak.exe 创建Pak 时用 -create = 时 文件的内容是 真实目录 …/…/…/游戏名字/content/xxxx

用 你通过获取pak 里的文件索引 就得到 后面的 …/…/…/游戏名字/content/xxxx 那么 如果你加载到gamecontent 目录的话
那么 路径是/Game/xxxx 如果你加载到enginecontent 目录的话 就是/Enigine/xxxx 如果你的资源还有map 的话 首先通过资源路径得到UObject 然后得到FAssetData 然后通过OpenMap 那个静态方法加载地图 参数为map 的路径 否则没在内存的话 会全盘搜索 费时间
http://dorgon.horizon-studio.net/archives/693
https://www.epicgames.com/unrealtournament/forums/showthread.php?19505-How-to-retrieve-the-map-name-URL-from-pak-files-(short-list-all-maps)