Addressables-Sample icon indicating copy to clipboard operation
Addressables-Sample copied to clipboard

The AsyncOperationStatus.Status are different between first load and second load

Open KeyleXiao opened this issue 5 years ago • 5 comments

https://forum.unity.com/threads/the-asyncoperationstatus-status-are-different-between-first-load-and-second-load.889975/

KeyleXiao avatar May 14 '20 06:05 KeyleXiao

Sampe1.cs.zip

Yesterday night , I found a bug in Addressables [1.1.10] o_O

When I loading error path , AsyncOperationStatus told me “None” , and try loading again AsyncOperationStatus told me “Failed” , I think the second status is right or the first status is a bug .

What’s the different between first load and second load ? ?

TestCode: Sampe1.cs

image

The First Click ! image

Then Click The Button Again ! We can see the “Right Error Info” , Status is Failed . image

KeyleXiao avatar May 14 '20 14:05 KeyleXiao

I found out the different between first load and second load , in fact when i click the load button , Addressable will execute InitializeAsync (the function is delay execute) . when i click load button again InitializeAsync function are complete . so the AsyncOperationStatus is right.

KeyleXiao avatar May 14 '20 15:05 KeyleXiao

image

KeyleXiao avatar May 14 '20 15:05 KeyleXiao

IEnumerator loadRes()
{
    yield return Addressables.InitializeAsync();
 
    var operationHandle = Addressables.LoadAssetAsync<GameObject>(loadPath);

    Debug.Log(operationHandle.Status.ToString());

    if (operationHandle.Status == AsyncOperationStatus.Failed)
    {
        Debug.Log("load failed");
        yield break;
    }
}

if you want to load asset like this, must run [ Addressables.InitializeAsync() ] function first.

Goodnight !

KeyleXiao avatar May 14 '20 15:05 KeyleXiao

Hi @KeyleXiao thanks for investigating this! One thing I would suggest is to avoid depending on the value of operationHandle.Status until after the operationHandle has completed. The operation is asynchronous so it's not guaranteed that the Status will always be the same value at a particular frame.

kirstenpilla avatar Jan 14 '22 20:01 kirstenpilla