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 How to simulate addressables download dependencies in development mode?

Discussion in 'Addressables' started by fugiimarie, Feb 14, 2022.

  1. fugiimarie

    fugiimarie

    Joined:
    Dec 19, 2021
    Posts:
    1
    I'm new to addressables, and am trying to simulate in unity how to use addressable to download dependencies (with a progress bar showing downloading progress).

    Scenario:
    I created 2 groups as in pic below:

    The scene in the pic will use the pic in group Texture New.

    In order to simulate downloading dependencies in unity, I used web hosting, and set to use remote build/load paths accordingly as in pic:

    Then I chose Simlulate Group and New Build (Default Build Script), and run in Unity.

    I wrote the following code for downloading dependencies (with preloadLabel = 'default' which is the label of the assets), and it works:
    Code (CSharp):
    1.  public class SceneLoader : MonoBehaviour
    2.     {
    3.         [SerializeField]
    4.         public AssetReference _scene;
    5.         public Slider slider;
    6.  
    7.         public AssetLabelReference preloadLabel;
    8.  
    9.         private void Start()
    10.         {
    11.             LoadScene(_scene);
    12.         }
    13.  
    14.         public void LoadScene(AssetReference scene)
    15.         {
    16.              
    17.     Addressables.ClearDependencyCacheAsync(preloadLabel);
    18.          
    19.             StartCoroutine(DownloadResource());
    20.         }
    21.  
    22.         protected virtual IEnumerator DownloadResource()
    23.         {
    24.             AsyncOperationHandle<long> getDownloadSize = Addressables.GetDownloadSizeAsync(preloadLabel);
    25.             yield return getDownloadSize;
    26.  
    27.             if (getDownloadSize.Result > 0)
    28.             {
    29.                 AsyncOperationHandle downloadDependencies = Addressables.DownloadDependenciesAsync(preloadLabel, false);
    30.  
    31.                 while (downloadDependencies.Status == AsyncOperationStatus.None)
    32.                 {
    33.                     float percentageComplete = downloadDependencies.GetDownloadStatus().Percent;
    34.            
    35.                     slider.value = percentageComplete;
    36.                     yield return null;
    37.                 }
    38.  
    39.                 Addressables.Release(downloadDependencies);
    40.                }
    41.         }

    Issue:
    The problem is when I tried to update my addressable assets, such as replacing an image of Label Skin1 to a new Image, then chose Update A Previous Build, and played in Unity, the old images of Label Skin1 still appeared in the scene, instead of the new image.

    I'm wondering if this has something to do with caching, so I used ClearDependencyCacheAsync as in the codes above, yet it's still not working.

    Could anyone please kindly help advise me what I'm doing wrong? Thanks!
     

    Attached Files:

  2. Spectra_7

    Spectra_7

    Joined:
    Oct 17, 2017
    Posts:
    33
    I am not much experienced with Addressables.

    For removing cache try this before starting the download.
    Code (CSharp):
    1. Caching.ClearCache();
    Also after updating contents are you uploading new files and catalog to your web host (that IP in your screenshot)?

    Do you see new content if you use Asset Database (faster)?
     
  3. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    736
    Hey all,

    So, you're actually building bundles and then hosting them locally using some web service. I think you'd be better served by changing Simulate Groups to Use Existing Build. You're actually building your content + putting your remote AssetBundles, content catalog json and catalog hash file in your locally hosted web service, I assume. This means you actually have bundles you want to "download" even though they're technically local.

    Simulate Groups mode, also known as Virtual Mode in the past if you've seen that terminology, just builds what we call VirtualAssetBundles. Then you can change the Simulate Groups settings to fake things like latency. It's a bit of a confusing feature. Simulate Groups mode should be able to be used how you want, in a way. It shouldn't actually require anything to be built, so your Update a Previous Build shouldn't matter for that Play mode script.

    @Spectra_7 has good suggestions. If you don't see anything different when you switch to AssetDatabase Mode then there might be a problem with your loading code. If you do see updated content with that mode, there may be an issue with Simulate Groups mode.

    If you do try and switch to Use Existing Build, since you actually are building content, you would need to clean the cache as Spectra says, prior to each test of DownloadSizeAsync.

    There's a bit of info here that explains the different play mode scripts.
     
  4. joanpescador

    joanpescador

    Joined:
    Dec 21, 2016
    Posts:
    122
    It would be so nice to get a clear tutorial in a recent LTS of how to load diferent catalog and content to remote and how to call this foreign catalogs and download their content.