Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Play Asset Delivery with Addressables

Discussion in 'Android' started by Thorax-, Aug 17, 2023.

  1. Thorax-

    Thorax-

    Joined:
    Feb 10, 2021
    Posts:
    20
    Hello! I am trying to implement Play Asset Delivery(PAD) in order to reduce the initial download size of our released game and allow us to add additional content in the future. Currently the game is set up to use Addressables (v1.21.12) with Unity 2020.3.30. The game has 100 levels separated in 2 seasons by 50 levels.

    For testing purposes I am trying to make season 2 to be downloaded on-demand and everything else is set as instal-time asset delivery. The size of the .aab before trying to do anything is 93.5MB when uploaded in Play store for testing. I am using this guide:
    https://github.com/Unity-Technologi.../master/README.md#advancedplay-asset-delivery

    I copied the scripts and assets from the sample project and I set up all my Addressables Groups to have the Play Asset Delivery Schema with instal-time delivery set for all except for the season 2 Addressable group, which is set to on-demand:

    Screenshot 2023-08-17 at 16.13.38.png

    I then build the Addressable Groups as described using the Play Asset Delivery Script:

    Screenshot 2023-08-16 at 16.35.20.png

    All goes well. I build the .aab and upload it for testing. Game launches and all levels are loading as normal and working without any issues. The Problem is the initial download size is the same as before adding PAD. I don't notice any delay when I am trying to open a level from season 2 - I am expecting that some delay should exist while the content is being downloaded for the first time. The memory that the game occupies on the device stays the same. Everything behaves as if there is no on-demand content and all assets are downloaded as instal-time.

    All files and folders are created as mentioned in the Sample project and i checked build.gradle and .json files are created correctly pointing to the assets that I marked as on-demand.

    Can someone point me to what I am missing here?
    I am loading the on-demand assets in the same way using the Addressables API.
    Once the Addressables are built all the .bundle files are located in the same folder ../com.unity.addressables/aa/Android/Android/
     
    buzazhyy likes this.
  2. Thorax-

    Thorax-

    Joined:
    Feb 10, 2021
    Posts:
    20
    Update:

    I didn't have the google play core plugin installed. Now I have it but the on-demand assets are not loading correctly.

    In Google developer console when the aab is uploaded for testing the Asset Packs are not displayed (CustomOnDemand and CustomFastFollow). Only "base" is there and it contains the whole game with all assets - I assume that because the size is the same as before starting to implement this PAD solution. I tried with the "Split Application Binary" option on and off. If I set it to ON the custom packs are still not displayed but the instal-time are separated in 2 categories now: base and UnityDataAssetPack - all my addressable groups are set as instal-time except the one which is set to on-demand:

    image_2023_08_18T13_04_28_549Z.png


    After debugging I found that when attempting to load an on-demand asset and the method AppBundleTransformFunc in PlayAssetDeliveryInitializeOperation.cs is called from the Addressables API then:

    PlayAssetDeliveryRuntimeData.Instance.BundleNameToAssetPack contains the "bundleName"
    PlayAssetDeliveryRuntimeData.Instance.AssetPackNameToDownloadPath does NOT contain the "assetPackName"

    Both the bundleName and the assetPackName are correct when I print them in the console.

    Additionally when the on-demand asset is loading the DownloadRemoteAssetPack method in class PlayAssetDeliveryAssetBundleProvider.cs is called. The callback CheckDownloadStatus never fires and there is no error caught by the try/catch.

    I can provide any additional information. Any help would be appreciated. Thanks!
     
    Last edited: Aug 18, 2023
  3. Thorax-

    Thorax-

    Joined:
    Feb 10, 2021
    Posts:
    20
    Update:

    Starting to think that different combination of Unity versions and Addressables versions are not able to provide a working PAD aab build. There is either an error when you try to make the build like this one:

    Screenshot 2023-08-21 at 17.49.11.png

    Or the build succeeds but the custom Asset packs are not recognised by the Google console.
    So I will try to get the correct combination of Unity version and Addressables version in order to make this work.
    I will come back to share my progress in case I have any.

    Edit:
    Whatever I do I can not get the bundle which is assigned to a custom asset pack to be put in the corresponding .assetpack folder by the PAD build script.

    @Aurimas-Cernius said that you "stopped moving files around" in here:
    https://forum.unity.com/threads/pad...for-custom-asset-bundle.1389945/#post-8753755

    Does this mean that not seeing the bundle files inside the CustomOnDemand folder is normal?

    I tried upgrading project to Unity 2021.3.20f1 but then I would get errors like these:
    image_2023_08_22T09_53_53_190Z.png image_2023_08_22T10_16_23_444Z.png
     
    Last edited: Aug 22, 2023
    buzazhyy likes this.
  4. buzazhyy

    buzazhyy

    Joined:
    Sep 3, 2016
    Posts:
    2
    We have the same problem as well. It would be really cool if all this worked. This is a very useful thing! In theory.
     
  5. Thorax-

    Thorax-

    Joined:
    Feb 10, 2021
    Posts:
    20
    Update:

    So here is what I did so far and I got a good progress:
    1. Use Unity 2020.3.30f1 and Addressables 1.19.19
    2. Get the Unity PAD Sample and copy the scripts as described.
    3. Use google plugins 1.7.0 because 1.8.0 or later are giving errors

    Some Debug Logs that I added trying to figure out what's the problem:

    View attachment 1292220

    View attachment 1292223

    Here is how I am loading the on-demand asset:

    Code (CSharp):
    1. private void LoadLevel()
    2. {
    3.     Debug.Log($"Loading Level: {currentLevel}");
    4.     var operation = Addressables.LoadAssetAsync<LevelSO>(levelPath);
    5.     operation.Completed += (asyncOperationHandle) =>
    6.     {
    7.         Debug.Log($"Loading level {currentLevel} is completed.");
    8.         if (asyncOperationHandle.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
    9.         {
    10.              Debug.Log("Getting Level prefab");
    11.              levelAsset = asyncOperationHandle.Result;
    12.              CurrentLevelPrefab = Instantiate(asyncOperationHandle.Result.LevelPrefab);
    13.         }
    14.     };
    15.  
    16.     operation.WaitForCompletion();
    17.  
    18.     Debug.Log($"Loading Operation is completed for level: {currentLevel}. Initialising managers...");
    19.      ...
    20. }
    When i try to load the level the printed lines are in the following order:
    Loading level: 75
    Trying to download pack: CustomOnDemand - this log is from PlayAssetDeliveryAssetBundleProvider.cs

    Nothing else gets printed. LevelSO is a Scriptable object containing the level prefab. Is it possible that the .WaitForCompletion() call is somehow blocking the download process and therefore nothing happens? In the same way I am loading the levels which are in the instal-time bundles and they are loading without problem.

    I download the test app from Play store - the size is reduced as expected because there is on-demand content.
    - Before starting the game the size occupied on the phone is 183MB
    - After first launch of game and NOT accessing any of the on-demand content the size occupied on the deivce increases to 206MB.
    - After the "Trying to download pack: CustomOnDemand" log the app now occupies 216MB, which means something got downloaded, but my game is stuck in the loading screen (which disappears normally once the level is loaded by the addressables api). I receive no errors or logs of any sort after that moment. The try/catch also doesn't throw any errors.

    I tried to set the bunndle with Pack Seaparately or Pack Together. Tried enabling/disabling 'Split Application Binary'. the on-demand bundle is correctly detected by Google:
    image_2023_08_25T11_45_51_598Z.png