Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Addressables.LoadAssetAsync is null

Discussion in 'Addressables' started by gugua, Jan 3, 2020.

  1. gugua

    gugua

    Joined:
    Jan 11, 2013
    Posts:
    32
    Hi all:
    I use the Addressables 1.5 and Unity2019 to RemoteLoad
    But everytime is null.
    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.AddressableAssets;
    6. using UnityEngine.ResourceManagement.AsyncOperations;
    7. using UnityEngine.U2D;
    8.  
    9. public class Test2 : MonoBehaviour
    10. {
    11.     //public AssetReference Ref;
    12.     GameObject Obj = null;
    13.     GameObject Obj2 = null;
    14.     AsyncOperationHandle<GameObject> loader;
    15.     AsyncOperationHandle<GameObject> loader2;
    16.     void Start()
    17.     {
    18.         //spriteAtlasReference.LoadAssetAsync().Completed += AtlasDone;
    19.         Addressables.LoadAssetAsync<GameObject>("Cube").Completed += OnLoadDone2;
    20.         //ss.sprite = sp.GetSprite("ui_spcard_01");
    21.     }
    22.  
    23.  
    24.     private void OnLoadDone2(UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle<GameObject> handle)
    25.     {
    26.         Debug.Log("22222");
    27.         // In a production environment, you should add exception handling to catch scenarios such as a null result.
    28.         loader2 = handle;
    29.         if (handle.Status == AsyncOperationStatus.Succeeded)
    30.         {
    31.             Obj2 = handle.Result;
    32.             Obj2 = Instantiate(Obj, transform.position, Quaternion.identity);
    33.         }
    34.     }
    35. }
    and setting
     

    Attached Files:

  2. Ak47-forever

    Ak47-forever

    Joined:
    Mar 1, 2015
    Posts:
    16
    Same happens to me... Did you find solution?
     
  3. rabishan-maharjan

    rabishan-maharjan

    Joined:
    Jul 3, 2016
    Posts:
    18
    Happens to me when loading SpriteAtlas by reference. but if i use key instead of reference to load SpriteAtlas, it works. Another problem is, SpriteAtlas.GetSprites() always returns null.
     
  4. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    762
    Hm, that's unfortunate. Have either of you filed a bug by chance? If not please do so.

    If you manually pack your SpriteAtlas before doing your Addressables content build does GetSprites still return null?
     
  5. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    I get also null when using this code:

    Code (CSharp):
    1. public T LoadAssetSync<T>(string address)
    2.     {
    3.         AsyncOperationHandle<T> handle = Addressables.LoadAssetAsync<T>(address);
    4.  
    5.         Debug.Log(handle.Status);
    6.  
    7.         StartCoroutine(WaitForLoadHandleFinish(handle));
    8.  
    9.         Debug.Log(handle.Result);
    10.         return handle.Result;
    11.     }
    12.  
    13.     IEnumerator WaitForLoadHandleFinish(AsyncOperationHandle handle)
    14.     {
    15.         yield return new WaitUntil(() => handle.IsDone == true);
    16.     }
    already regretting switching to addressables
     
  6. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    218
    That wont work as you're not waiting for the handle to complete, your just creating a coroutine that waits but then doesn't do anything, the LoadAssetSync function will return instantly.
    You will need to wait on that coroutine inside LoadAssetSync, but that wont be sync as you would need to make LoadAssetSync a coroutine as well.
    Best just upgrade to a newer version of addressables and use the new sync method.
     
  7. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219

    Thanks, yeah i did and the sync functions they wrote are working. Just makes me nervous using a beta version in production.