Search Unity

Addressables stops loading at certain points

Discussion in 'Addressables' started by Niiilsen, Mar 27, 2020.

  1. Niiilsen

    Niiilsen

    Joined:
    Aug 26, 2012
    Posts:
    3
    I have come across a really weird issue where my loading sequence stops at certain points when using PlayMode - use exising build (use asset database works just fine). However, when I'm in the editor and if I maximize and then minimize my game view the loading continues for a while and then stops again until I repeat the action. If I do this a couple of times the loading eventually completes and the game works as intended.. I'm using Addressables 1.6.2.
    I'm rather new to addressables so I'm not sure if I'm doing something wrong or if this is a bug.

    More details below:

    I have a object pool manager that first loads all scriptable object pool assets. They hold data like poolname, size and a asset reference to the pool prefab. Loading these works just fine and the Completed callback is reached, but when I start looping through the result list of pools to initialize them, it comes to a stop at certain points.

    ObjectPoolManager:
    Code (CSharp):
    1. public void Start()
    2. {
    3.        Addressables.LoadAssetsAsync<ObjectPool>("object_pool", null).Completed += (AsyncOperationHandle<IList<ObjectPool>> op) => OnAssetsLoaded(op, callback);
    4. }
    5.  
    6. private void OnAssetsLoaded(AsyncOperationHandle<IList<ObjectPool>> op, System.Action callback)
    7. {
    8.         StartCoroutine(InitializePools(op.Result, callback));
    9. }
    10.  
    11. // Initialize one pool at a time
    12. private IEnumerator InitializePools(IList<ObjectPool> pools, System.Action callback)
    13. {
    14.      foreach (var pool in objectPools)
    15.      {
    16.             bool proceed = false;
    17.             pool.Initialize(() => proceed = true);
    18.             while (!proceed) { yield return null; } // Wait for pool to finish
    19.      }
    20.      callback();
    21. }
    22.  
    Each object pool initializes by first loading their asset reference and then instantiating the object using GameObject.Instantiate. It's the LoadAssetAsync.Completed callback that never gets called and thus making everything come to a stop..

    ObjectPool (scriptable object)
    Code (CSharp):
    1. private Transform poolParent;
    2.  
    3. public void Initialize(System.Action callback)
    4. {
    5.      poolParent = new GameObject().transform;
    6.      prefabAssetReference.LoadAssetAsync<GameObject>().Completed += (AsyncOperationHandle<GameObject> op) => OnPoolObjectLoaded(op, callback);
    7. }
    8.  
    9. private void OnPoolObjectLoaded(AsyncOperationHandle<GameObject> op, System.Action callback)
    10. {
    11.      for(int i = 0; i < poolsize; i++)
    12.      {
    13.           Instantiate(prefabAssetReference.Asset, poolParent);
    14.      }
    15.      callback(); //Tell object pool manager to proceed to the next pool
    16. }
    It always finish initializing the first pool which is just a single gameobject with a script component attached, but when it reaches the second pool which references a somewhat complex particle system it stops. The remaining pools are also mostly particle systems and projectiles with more that one single gameobject. I don't see why this should matter but I thought I'd mention it.

    Other
    - All assets are built in addressables groups.
    - As mentioned minimizing the game view seems to trigger some kind of event that makes the loading continue.

    That's all!
     
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,822
    I'll kick this over to the team, so they can have a look.
     
  3. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    So I think the Unity game view automatically pauses when Unity loses focus. I can't remember off the top of my head if it occurs when the game view loses focus to other windows inside Unity though.

    You could try adding Application.runInBackground = true; to the top of your script and see if that help you out any. Other than that I'm really not quite sure why this might be happening.
     
  4. Niiilsen

    Niiilsen

    Joined:
    Aug 26, 2012
    Posts:
    3
    The RunInBackground was already set to true in the player settings. The issue occurs in build aswell.

    I can't really tell if I've done something wrong either since it's able to load with some manual help. I'm on version 2018.4.16f1, don't know if that could be a factor