WaitForCompletion always hangs in 2021.3.7 / Addressables 1.19.15

[Note that I’m unable to edit subject. The affected version is 2021.2.7. I assume this will be fixed before LTS :slight_smile: ]

As far as I can see, WaitForCompletion() is completely broken and will hang the editor (or any built player) in Unity 2021.2.7 / Addressables 1.19.15. The same code works as expected in our live 2020.3 project.

A bug report will follow as soon as I’ve made a custom project. But setting up a new project and configuring/building/uploading to addressable servers takes time, and this issue appears trivially reproducible with no custom setup so reporting here first for efficiency.

Instructions:

  • Create a new empty scene.
  • Create a prefab (a basic cube is sufficient reproduce) and make addressable.
  • Create a new gameobject in the empty scene and attach the code below. Point assetReferenceGameObject at the cube prefab (or whatever) you just made.
  • Run project in “Use Asset Database”, observe works correctly.
  • Build data, upload to your web server, run using “Use Built Data”, observe editor hangs on entering playmode.
  • If required, confirm that commenting in the yield line instead of WaitForCompletion (i.e. making things async) will work
  • Note that same code works as expected in 2020.3.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;

public class HangOnLoadAddressable : MonoBehaviour
{
    public AssetReferenceGameObject assetReferenceGameObject;
    public GameObject instantiatedGameObject;

    // Start is called before the first frame update
    IEnumerator Start()
    {
        if (!instantiatedGameObject)
        {
            var asyncOpHandle = assetReferenceGameObject.InstantiateAsync(this.transform);

            //yield return asyncOpHandle;
            asyncOpHandle.WaitForCompletion();

            instantiatedGameObject = asyncOpHandle.Result;
        }

        yield break; // Here just to allow compilation
    }
}

Update. When attempting to make a minimal repro of this outside of the project, we couldn’t.

It appears this is a result of ??some addressables setting during the upgrade??. Nuking all of our AddressableAssetsData folder, letting Addressables 1.19.x re-create that folderwith default settings, then recreating the asset groups (which contain thousands of assets) by copying and pasting YAML from our old groups in a text editor fixed everything.

I just saw Addressables 1.19.17 contains several WaitForCompletion fixes:
https://docs.unity3d.com/Packages/com.unity.addressables@1.19/changelog/CHANGELOG.html