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

EditorAsset getter : null reference

Discussion in 'Addressables' started by RDeluxe, Nov 16, 2018.

  1. RDeluxe

    RDeluxe

    Joined:
    Sep 29, 2013
    Posts:
    117
    Hi,

    While creating a new
    AssetReferenceT<T>
    , obviously the editorAsset and the _guid are null.

    This is creating a bug in the editorAsset getter as
    m_assetGUID
    is null

    Code (CSharp):
    1.  public Object editorAsset
    2.         {
    3.             get
    4.             {
    5.                 if (m_cachedAsset != null)
    6.                     return m_cachedAsset;
    7.                 return (m_cachedAsset = UnityEditor.AssetDatabase.LoadAssetAtPath<Object>(UnityEditor.AssetDatabase.GUIDToAssetPath(m_assetGUID.ToString())));
    8.             }
    9. }
    I fixed it quickly by editing

    Code (CSharp):
    1. return (m_cachedAsset = UnityEditor.AssetDatabase.LoadAssetAtPath<Object>(UnityEditor.AssetDatabase.GUIDToAssetPath(m_assetGUID?.ToString())));
     
  2. RDeluxe

    RDeluxe

    Joined:
    Sep 29, 2013
    Posts:
    117
    Hi again,

    Am I doing something wrong or is this a bug ?
     
  3. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Most likely we need to add an early-out to that getter if both the cached asset and the guid are null. I've added a note to do that.

    I just say "most likely" because we generally have been looking at the AssetReference workflow via components exposing refrences and them being set in the editor. It sounds like you are driving this from code. We know that needs to work, but we would like to spend at least a brief amount of time checking on the implications before implementing something.

    Thanks for letting us know about this one.

    -Bill
     
  4. RDeluxe

    RDeluxe

    Joined:
    Sep 29, 2013
    Posts:
    117
    I'm working with List<AssetReference>, and so this happens a lot.
    I filed another bug due to AssetReference not displaying in List<> in the editor.
     
  5. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    813