Search Unity

Use Addressables API to load sprite in Resources : failed

Discussion in 'Addressables' started by gyx920820, Dec 11, 2018.

  1. gyx920820

    gyx920820

    Joined:
    Oct 8, 2015
    Posts:
    35
    version 0.4.8

    I have a single sprite texture in Resources: Assets/Resources/Image.png
    It's not Addressable

    When I load like this: Resources.Load<Sprite>("Assets/Resources/Image"), it's OK.

    But when I load like this: Addressables.LoadAsset<Sprite>("Assets/Resources/Image").Completed+=call back func
    In call back func,obj.Status = AsyncOperationStatus.Failed
     
  2. gyx920820

    gyx920820

    Joined:
    Oct 8, 2015
    Posts:
    35
    I tried this, and it's ok:
    Addressables.LoadAsset<Texture2D>("Assets/Resources/Image")
     
  3. gyx920820

    gyx920820

    Joined:
    Oct 8, 2015
    Posts:
    35
    I found the code in LegacyResourcesProvider.cs
    :
    Code (CSharp):
    1. public InternalProviderOperation<TObject> StartOp(IResourceLocation location)
    2.             {
    3.                 m_result = null;
    4.                 m_requestOperation = Resources.LoadAsync<Object>(location.InternalId);
    5.                 if (m_requestOperation.isDone)
    6.                     DelayedActionManager.AddAction((System.Action<AsyncOperation>)OnComplete, 0, m_requestOperation);
    7.                 else
    8.                     m_requestOperation.completed += OnComplete;
    9.                 return base.Start(location);
    10.             }
    It Load Object, then convert to TObject. This means it will load the default type of asset....