UE4 Custom Pak load

Hello,

I got a problem when loading assets from .pak from builded application.

This is my workflow:

1 - Import 3D model (fbx + texture), so in my project I got:

  • material.uasset

  • skeletalMesh.uasset

  • physicsAsset.uasset

  • skeleton.uasset

  • texture.uasset

2 - I pak all these assets into a pak file with UnrealPak command line:

UnrealPak.exe “.path/to/6737.pak” -Create=“path/to/filesToPak.txt” -encryptionini -platform=Windows -installed -UTF8Output -multiprocess -patchpaddingalign=2048 -abslog=“path/to/6737.log”

3 - Unreal process:

  • Mount pak to path

  • Find files in MountPoint (files found with success)

  • Load files

This code work in Editor perfectly. I can load and build my character but when builded for Windows platform, I got this error when I try to load uasset:

Warning: Unable to load package
(…/…/…/UE4PakFiler/Content/UNPAK/6737_M.uasset).
Package contains EditorOnly data which
is not supported by the current build.

Code:

void UMyClass::TestLoad(TArray<UObject*> &Classes)

{

	IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
	FPakPlatformFile* PakPlatformFile = new FPakPlatformFile();
	PakPlatformFile->Initialize(&PlatformFile, TEXT(""));
	PakPlatformFile->InitializeNewAsyncIO();
	FPlatformFileManager::Get().SetPlatformFile(*PakPlatformFile);

	const FString PakFilename = TEXT("C:\\Users\\MAX\\Desktop\\CustomPak\\6737.pak");
	FPakFile PakFile(&PlatformFile, *PakFilename, false);

	if (PakFile.IsValid())
	{
		UE_LOG(LogClass, Warning, TEXT("===== Pak file is valid ====="));
	}

	
	FString MountPoint = "";
#if WITH_EDITOR
	MountPoint = FString("E:/Silkke/UE4/UE4PakFiler/Content/UNPAK");
	//MountPoint = FPaths::ProjectContentDir() + "UNPAK";
#else
	//MountPoint = FPaths::ProjectPersistentDownloadDir();
	MountPoint = FPaths::ProjectContentDir() + "UNPAK";
#endif
	PakFile.SetMountPoint(*MountPoint);

	if (!PakPlatformFile->Mount(*PakFilename, 0, *MountPoint))
	{
		UE_LOG(LogClass, Warning, TEXT("Mount failed"));
		return;
	}

	UE_LOG(LogClass, Warning, TEXT("===== Pak mounted with success '%s' ====="), *PakFilename);
	UE_LOG(LogClass, Warning, TEXT("FileName: %s"), *PakFilename);
	UE_LOG(LogClass, Warning, TEXT("Mountpoint: %s"), *PakFile.GetMountPoint());

	TArray<FString> FileList;
	PakFile.FindFilesAtPath(FileList, *PakFile.GetMountPoint(), true, false, true);
	FStreamableManager StreamableManager;

	UE_LOG(LogClass, Warning, TEXT("Files found: %d"), FileList.Num());
	if (FileList.Num() > 0)
	{
		UE_LOG(LogClass, Warning, TEXT("Files browse..."));

		for (auto f : FileList)
		{
			FString AssetShortName = FPackageName::GetShortName(f);
			FString LeftStr;
			FString RightStr;
			AssetShortName.Split(TEXT("."), &LeftStr, &RightStr);
			//FString AssetName = FPaths::ProjectPersistentDownloadDir() + "/" + LeftStr + TEXT(".") + LeftStr;
			FString AssetName = TEXT("/Game/UNPAK/") + LeftStr + TEXT(".") + LeftStr;
			//FString AssetName = TEXT("/Game/6737/") + LeftStr + TEXT(".") + LeftStr;

			UE_LOG(LogClass, Warning, TEXT("AssetName: %s"), *AssetName);

			FStringAssetReference r = AssetName;
			UObject* LoadObject = StreamableManager.LoadSynchronous(r, true);

			if (LoadObject != nullptr)
			{
				UE_LOG(LogClass, Warning, TEXT("Asset loaded with success: %s"), *AssetName);
				Classes.Add(LoadObject);
			}
			else
			{
				UE_LOG(LogClass, Warning, TEXT("Asset failed to load: %s"), *AssetName);
			}
		}
	}

	if (PakPlatformFile->Unmount(*PakFilename))
		UE_LOG(LogClass, Warning, TEXT("===== Pak unmounted with success '%s' ====="), *PakFilename);
}

If someone can help me ? :slight_smile:

Thanks,

~Nyudeb

I found that the problem was how to package my assets… When I create a pak from the editor (build), I can load them. But when I create the pak via UnrealPak, something must be missing that makes the assets usable only via the Editor…

Same issue here, however if you set the build configuration to Shipping, there is no errors but it does not load the asset from the pak file.
I tried to create the pak file from the editor, but that I am still not able to load the asset at runtime.

I found the solution. You need to cook .uasset you want to use in Dev / Ship build. And you just need to drag’n’drop asset in editor + pak them to use them in Editor.
So finally, you need 2 different .pak: cooked and uncooked