Search Unity

[0.7.5] How to know if a remote asset is cached?

Discussion in 'Addressables' started by bruno_1308, May 7, 2019.

  1. bruno_1308

    bruno_1308

    Joined:
    May 16, 2018
    Posts:
    14
    Hello everyone, my use case is as follows:
    Code (CSharp):
    1.  
    2. async void ClickedOnPlay(){
    3.     if(AddressablesHasRemoteAssetCached){
    4.         StartGame();
    5.     } else {
    6.         await DownloadAsset(); //But DO NOT Call StartGame
    7.         //The next time player clicks on Play, the 'if' statement will be true because AddressablesHasRemoteAssetCached will be true (pretending the download will be finished)
    8.     }
    9. }
    10.  

    So my question is: how can I know if an remote asset is cached?

    Thanks in advance!
     
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    In theory, GetDownloadSizeAsync should work, but as noted in the method name, it's async. You could also just download the thing. If what you need is cached, the download will callback during the LateUpdate. It's possible (though I haven't tested it), that he handle returned by DownloadDependenciesAsync will actually have isDone==true immediately. Again, haven't tested that.
     
    bruno_1308 likes this.