Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Recommendations on implementing a failover system in case of a temporary server unavailability

Discussion in 'Addressables' started by tencnivel, May 31, 2019.

  1. tencnivel


    Sep 26, 2017
    When the system fails at retrieving an asset (eg. because the server hosting the bundle is down) the result is null and the AsyncOperationHandle.Status is set to 'Failed'.

    In my scenario, this unavailability is temporary (another server is shortly taking over for the same URL) and I would like to do the following:
    1. Make the game pause for a few milliseconds
    2. Call again the actions that failed
    The problem is that somehow the Addressables system considers that the bundle has already been retrieved and new calls to `Addressables.LoadAssetAsync<T>(my_string)` do not result in an HTTP call to the server.

    My first attempt has been to call `Caching.ClearCache()` in case a first attempt to load an asset had failed. But it doesn't work, the Addressables system still considers that the bundle has already been retrieved.

    Here is an over simplified version of my code to reproduce the problem.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.AddressableAssets;
    3. public class BasicReference : MonoBehaviour
    4. {
    6.     string _assetRef = "Assets/Prefabs/Cube.prefab";
    7.     private GameObject _loadedAsset;  
    8.     private bool _tryAgain = false;
    10.     void Start () {
    11.         Caching.ClearCache(); // clear the cache when game starts
    12.     }
    14.     public void SpawnThing()
    15.     {
    16.         // If a previous loading had failed, we clear the cache in order to force the addressables system to go retrieve the bundle to the content server
    17.         if (_tryAgain) {
    18.             Caching.ClearCache(); // DOESN'T HAVE THE EXPECTED RESULT :(
    19.         }
    21.          Addressables.LoadAssetAsync<GameObject>(this._assetRef).Completed += OnLoadDone;
    23.     }
    25.     private void OnLoadDone(UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle<GameObject> obj)
    26.     {
    27.         // If the loading failed we set a flag
    28.         if (obj.Result == null) {
    29.             this._tryAgain = true;
    30.         }
    32.         Instantiate(obj.Result);
    33.     }
    35. }