I am using the recommended code structure (shown below) for loading Addressables with WaitForCompletion.
void Start()
{
//Basic use case of forcing a synchronous load of a GameObject
var op = Addressables.LoadAssetAsync<GameObject>("myGameObjectKey");
GameObject go = op.WaitForCompletion();
//Do work...
Addressables.Release(op);
}
My specific implementation is below:
public AudioClip LoadAudioClip(string key)
{
var op = Addressables.LoadAssetAsync<AudioClip>(key);
AudioClip ac = op.WaitForCompletion();
Addressables.Release(op);
return ac;
}
The code above works perfectly when running in Editor.
However, when I run the same code built for Windows Build and step through with Unity Debugger, the object (ac) is still populated correctly by the WaitForCompletion() line, but then ac is reset to null by the Addressables.Release() line.
If I comment out the Addressables.Release(op) line, then the code also works perfectly in Windows Build, so I know the setup of my Addressables and groups are correct. This makes no sense and is not a viable solution, since the Unity docs indicate that Addressables.Release is mandatory to prevent memory leaks. Any ideas?