Load assets from mounted Pak files

I am currently studying how to loads assets from .pak that packed by unrealpack.exe , and I have already gained some results.There are relatively few materials, if necessary, you can refer to my plan.

i have load and create a UUserWidget.

There are a few points to note.

I currently only implement creating a component and displaying it.

1.const auto& mountPoint = pPakFile->PakGetMountPoint();
FPackageName::RegisterMountPoint(“/DLG/”, pakContentPath);
i register this pack like this when PakFile is loaded. then we can find the asset at “/DLG/PakTest.PakTest_C”

  1. when we want to create the asset,we should use the code ,i have tryed to use function “loadobject” loadclass,and all failed.
		FStringClassReference clsRef = sAssetFile;
		//AMyActor is my own c++ implemented actor that inherited from AActor
		UObject* pObject = clsRef.TryLoad();

or

		FStringClassReference MyClassRef(sAsset);
		return MyClassRef.TryLoadClass<T>();
  1. Assets are best to be independent or the directory is positive or not, otherwise an error may be reported that the dependent package does not exist

4.The packaged file that named .pak must be cooked

5.UE working mode is developer

class CxPakLoader
{
public:
	CxPakLoader() {}
	~CxPakLoader() {}

	bool Init(FString const& sPakPath)
	{
		pNewPakPlatForm = new FPakPlatformFile();
		pPlatformFile = &FPlatformFileManager::Get().GetPlatformFile();
		if (!pNewPakPlatForm->Initialize(pPlatformFile, TEXT("")))
			return false;
		// Not sure about this, see: https://answers.unrealengine.com/questions/574388/how-to-mount-a-pak-file-at-game-content-directory.html
		pNewPakPlatForm->InitializeNewAsyncIO();
		// Now give the new PlatformFile to the engine.
		FPlatformFileManager::Get().SetPlatformFile(*pNewPakPlatForm);
		pPakFile = new FPakFile(pPlatformFile, *sPakPath, false);
		const auto& mountPoint = pPakFile->PakGetMountPoint();
		pNewPakPlatForm->Mount(*sPakPath, 4, *mountPoint);
		FString pakContentPath = mountPoint;
		FPackageName::RegisterMountPoint("/DLG/", pakContentPath);
		//TArray<FString> AssetList;
		//pPakFile->FindPrunedFilesAtPath(AssetList, *pPakFile->GetMountPoint(), true, false, true);
		return true;
	}

	//"/DLG/PakTest.PakTest_C"
	UObject* FindObject(FString const& sAssetFile)
	{
		FStringClassReference clsRef = sAssetFile;
		//AMyActor is my own c++ implemented actor that inherited from AActor
		UObject* pObject = clsRef.TryLoad();
		return pObject;
	}

	template <class T>
	TSubclassOf<T> TryLoadClass(FString const& sAsset) {
		FStringClassReference MyClassRef(sAsset);
		return MyClassRef.TryLoadClass<T>();
	}

	void UnInit()
	{

	}

private:
	FPakFile* pPakFile = NULL;
	IPlatformFile* pPlatformFile = NULL;
	FPakPlatformFile* pNewPakPlatForm = NULL;
};

//UClass* BP_PakTestClass = LoadClass<AActor>(nullptr, TEXT("Blueprint'/Game/DLC/BP_PakTest1.BP_PakTest1_C'"));
//if (BP_PakTestClass) GetWorld()->SpawnActor<AActor>(BP_PakTestClass, FVector::ZeroVector, FRotator::ZeroRotator);

bool UCxActor::LoadPak(const FString& PakPath)
{
	CxPakLoader xPakLoader;
	xPakLoader.Init(PakPath);
	TSubclassOf<UUserWidget> pSubClass = xPakLoader.TryLoadClass<UUserWidget>("/DLG/PakTest.PakTest_C");

	if (pSubClass) {
		UUserWidget* TestWidget = UWidgetBlueprintLibrary::Create(GetWorld(), pSubClass, NULL);
		if (TestWidget)
			TestWidget->AddToViewport();
		OutputDebugString(L"------------xPakLoader.FindObject-------Success---------\r\n");
		return true;
	}
	else {
		OutputDebugString(L"------------xPakLoader.FindObject-------Failed---------\r\n");
		return true;
	}

	return false;
}