Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

1.16.10 Null Reference on AssetReferenceDrawer

Discussion in 'Addressables' started by CDF, Nov 17, 2020.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,282
    Getting this after upgrading to 1.16.10 on an object that has an AssetReferenceSprite:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEditor.AddressableAssets.GUI.AssetReferenceDrawer.DrawSubAssetsControl (UnityEditor.SerializedProperty property, System.Collections.Generic.List`1[T] subAssets) (at Library/PackageCache/com.unity.addressables@1.16.10/Editor/GUI/AssetReferenceDrawer.cs:489)
    3. UnityEditor.AddressableAssets.GUI.AssetReferenceDrawer.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at Library/PackageCache/com.unity.addressables@1.16.10/Editor/GUI/AssetReferenceDrawer.cs:278)
    4. UnityEditor.PropertyDrawer.OnGUISafe (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at <3037c1046402403280ab8b0782ca806f>:0)
    5. UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <3037c1046402403280ab8b0782ca806f>:0)
    6. UnityEditor.GenericInspector.OnOptimizedInspectorGUI (UnityEngine.Rect contentRect) (at <3037c1046402403280ab8b0782ca806f>:0)
    7. UnityEditor.UIElements.InspectorElement+<>c__DisplayClass58_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <3037c1046402403280ab8b0782ca806f>:0)
    8. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    9.  
    Downgraded to 16.7 and all is fine.
     
    lonelywolf317 likes this.
  2. ReSY

    ReSY

    Joined:
    May 5, 2013
    Posts:
    4
    I have the same issue in 1.16.10. In my case, it seems that m_AssetRefObject.SubOjbectType is null. I fixed it by adding extra check to AssetReferenceDrawer.cs on line 489. Correct code below but I'm not sure if it is actually correct

    Code (CSharp):
    1. if (subAsset == null || m_AssetRefObject.SubObjectName == objName &&
    2.                     m_AssetRefObject.SubOjbectType != null
    3.                     && subAsset.GetType().AssemblyQualifiedName == m_AssetRefObject.SubOjbectType.AssemblyQualifiedName)
    4.                     selIndex = i;
     
    lonelywolf317 likes this.
  3. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    513
    sigh

    I have submitted bug report# 1294006 because they're not going to fix something without one.

    My temp solution at this point is to remove this condition out of the if as it appears that the "m_AssetRefObject.SubOjbectType" is always null (can you fix the typo while you fix this bug please?).

    && subAsset.GetType().AssemblyQualifiedName == m_AssetRefObject.SubOjbectType.AssemblyQualifiedName
     
    lonelywolf317 likes this.
  4. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,282
    Sprites are Addressables nemesis
     
    lonelywolf317 likes this.
  5. ReSY

    ReSY

    Joined:
    May 5, 2013
    Posts:
    4
    In my case, I upgraded from 1.8.5 to 1.16.10. After that, the AssetReferenceSprite links to sprites are no longer displayed in the property inspector. An error message is displayed with null exception. In version 1.8.5 m_SubObjectName is serialized and that was enough. In version 1.16.10, m_SubObjectType is also serialized. But after upgrading to the new version, the m_SubObjectName property is filled and m_SubObjectType contains null. To fix everything, I had to add the check that I wrote about above, and then in the inspector I need to re-select AssetReferenceSprite and specify the SubObject then everything is filled in correctly.

    Metadata Before:

    picture:
    m_AssetGUID: 0680d093317f0bd40bec902a18dc3c85
    m_SubObjectName: Bg2
    m_SubObjectType:

    Metadata After:

    picture:
    m_AssetGUID: 0680d093317f0bd40bec902a18dc3c85
    m_SubObjectName: Bg2
    m_SubObjectType: UnityEngine.Sprite, UnityEngine.CoreModule, Version=0.0.0.0,
    Culture=neutral, PublicKeyToken=null
     
    lonelywolf317 likes this.
  6. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,796
    Thank you for the bug report! I know it's frustrating, but those bug reports are incredibly helpful when it comes to squashing these bugs. :)
     
    lonelywolf317 likes this.
  7. lonelywolf317

    lonelywolf317

    Joined:
    Dec 7, 2020
    Posts:
    1
    ffs i have the same error.