Mounting .pak file screws up asset loading in Windows

Hello, I have strange behavior on 4.17

I made some .pak files using UnrealPak and mounted it in runtime. It compiled and worked as expected in Android. But in windows, engine cannot find most of assets after mounting pak even asset file was not inside in the pak file.

I used code like this:

void UMyGameInstance::Init()
{
	Super::Init();

	auto PakPlatformFile = static_cast<FPakPlatformFile*>(FPlatformFileManager::Get().FindPlatformFile(TEXT("PakFile")));
	if (PakPlatformFile == nullptr)
	{
		PakPlatformFile = static_cast<FPakPlatformFile*>(FPlatformFileManager::Get().GetPlatformFile(TEXT("PakFile")));
		if (PakPlatformFile->Initialize(&FPlatformFileManager::Get().GetPlatformFile(), TEXT("")))
		{
			UE_LOG(LogTemp, Log, TEXT("created new FPakPlatformFile"));
			FPlatformFileManager::Get().SetPlatformFile(*PakPlatformFile);
		}
		else
		{
			UE_LOG(LogTemp, Error, TEXT("cannot initialize patch file!"));
		}
	}

	check(PakPlatformFile);

	FString path = FPaths::GameSavedDir() / TEXT("Characters.pak");
	bool ret = PakPlatformFile->Mount(*path, 200);
	check(ret);
}

As a note, just resetting platform file is not cause the problem. When after pak file mounted explicitly, the problem arises.

And I tried replacing PakPlatformFile->Mount() to FCoreDelegates::OnMountPak.Execute(), but no luck. Is it a bug? Or I might done a mistake?

https://github.com/EpicGames/UnrealEngine/pull/3548

I noticed there is some fixing is on going. Looking forward to the issue being solved :frowning:

In case the default platform file mana=get is not PakFile, you need to restore it once you are done mounting the pak. This is what my custom UndoSetPakPlatformFile does.

  1. SetPakPlatformFile

  2. mount and do stuff …

  3. UndoSetPakPlatformFile

  4. Everything should be fine now.

    IPlatformFile *PreviousPlatformFile = nullptr; // static init
    bool CommonFunctionLibrary::SetPakPlatformFile()
    {
    	FPakPlatformFile* PakFileMgr = (FPakPlatformFile*)(FPlatformFileManager::Get().FindPlatformFile(TEXT("PakFile")));
    	if (PakFileMgr == nullptr)
    	{
    		conoutf('I', "PakFile is null. Trying to initialize it ...");
    		FPakPlatformFile *PlatformFile = new FPakPlatformFile;
    
    		if (!PlatformFile->Initialize(&FPlatformFileManager::Get().GetPlatformFile(), TEXT("")))
    		{
    			conoutf('E', "FPakPlatformFile failed to initialize");
    			return false;
    		}
    
    		PlatformFile->InitializeNewAsyncIO();
    
    		PreviousPlatformFile = &FPlatformFileManager::Get().GetPlatformFile();
    		FPlatformFileManager::Get().SetPlatformFile(*PlatformFile);
    
    		conoutf('I', "PakFile is fine (just set)");
    	}
    	else
    	{
    		conoutf('I', "PakFile is fine");
    	}
    
    	return true;
    }
    
    void CommonFunctionLibrary::UndoSetPakPlatformFile()
    {
    	// return previous platform file manager to the top of the chain, so Unreal doesn't lose it's references
    	if (PreviousPlatformFile != NULL)
    	{
    		conoutf('I', "PakFile restored");
    		FPlatformFileManager::Get().SetPlatformFile(*PreviousPlatformFile);
    		PreviousPlatformFile = nullptr;
    	}
    }
    

can you please explain how to generate pak files for android and utilize them, have successfully generated and utilized for windows but don’t know how to do this for android mobile