// Fill out your copyright notice in the Description page of Project Settings. #include "PakProject.h" #include "PakProjectGameMode.h" #include "Runtime/PakFile/Public/IPlatformFilePak.h" //If I run the code in the editor mode(Both Constructer and BeginPlay),every thing is fine APakProjectGameMode::APakProjectGameMode() { //After packaging, If I run the code here,every thing work fine,I can load the UObject //LoadPak(); } void APakProjectGameMode::BeginPlay() { //After packaging,If I run the code here,I can mount the pak file ,but cannot load the UObject because there are editor only data in the pak file. LoadPak(); } void APakProjectGameMode::LoadPak() { FString SaveContentDir = FPaths::GameContentDir() + TEXT("Pak/OutPak.pak"); IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); FPakPlatformFile* PakPlatformFile = new FPakPlatformFile(); PakPlatformFile->Initialize(&PlatformFile, TEXT("")); FPlatformFileManager::Get().SetPlatformFile(*PakPlatformFile); FPakFile PakFile(*SaveContentDir, false); FString MountPoint(FPaths::EngineContentDir()); if (PakPlatformFile->Mount(*SaveContentDir, 0, *MountPoint)) { UE_LOG(LogClass, Log, TEXT("Mount Success")); TArray FileList; PakFile.FindFilesAtPath(FileList, *PakFile.GetMountPoint(), true, false, true); FStreamableManager StreamableManager; 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, Log, TEXT("Can not Load asset...")) } } else { UE_LOG(LogClass, Error, TEXT("Mount Failed")); } }