Problem with accessing mounted On-Demand pak file (GooglePAD)

Rakib Rahaman
Sun, 11 Jun 2023 16:06:03 +0000
Mobile

Hello everyone,

I’m facing an issue with accessing the assets within a mounted On-Demand pak file (GooglePAD) in my Unreal Engine project. The pak file mounts successfully, but the assets contained within it are either invalid or cannot be found after mounting.

Here is a snippet of the code I’m using to mount the pak file:

void AMyGameModeBase::MountPakFile(FString PakFilePath, const FString& PakFileName)
{
    if (!PakFilePath.EndsWith(TEXT("/")))
    {
        PakFilePath += TEXT("/");
    }
    const FString FullPakFilePath = PakFilePath + PakFileName + TEXT(".pak");

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

    #if PLATFORM_ANDROID
        if (PlatformFile.FileExists(*FullPakFilePath))
    #else
        if (true)
    #endif
    {
        LogWriteMessage(TEXT("File Exists"), FColor::Green);

        bIsSuccess = PakPlatformFile->Mount(*FullPakFilePath, 0);
        if (bIsSuccess)
        {
            LogWriteMessage(("Pak Mounted Successfully"), FColor::Green);

            FString ScanPoint = TEXT("/Game");
            FAssetRegistryModule& assetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));
            IAssetRegistry& assetRegistry = assetRegistryModule.Get();
            assetRegistry.ScanPathsSynchronous({ *ScanPoint }, false);

            // Check whether the assets are valid or not

            TArray<FAssetData> AssetData;
            assetRegistry.GetAllAssets(AssetData, false);

            LogWriteMessage(TEXT("Getting All Asset Name:"), FColor::Red);
            for (int32 i = 0; i < AssetData.Num(); ++i)
            {
                if (AssetData[i].GetAsset() != nullptr)
                {
                    // .....
                }
                else
                {
                    LogWriteMessage(FString::Printf(TEXT("%s/%s is not a valid object"), *AssetData[i].AssetName.ToString(), *AssetData[i].AssetClass.ToString()), FColor::Red);
                }
            }
        }
    }
}

I have verified that the pak file exists before mounting it, and the mounting process seems to be successful. However, it doesn’t work!

I would greatly appreciate any insights or suggestions on how to resolve this issue. Has anyone encountered a similar problem with accessing assets from mounted pak files? Are there any additional steps or considerations I should be aware of?

Thank you in advance for your help!

2 posts - 2 participants