1.16.10 Null Reference on AssetReferenceDrawer

Getting this after upgrading to 1.16.10 on an object that has an AssetReferenceSprite:

NullReferenceException: Object reference not set to an instance of an object
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)
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)
UnityEditor.PropertyDrawer.OnGUISafe (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at <3037c1046402403280ab8b0782ca806f>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <3037c1046402403280ab8b0782ca806f>:0)
UnityEditor.GenericInspector.OnOptimizedInspectorGUI (UnityEngine.Rect contentRect) (at <3037c1046402403280ab8b0782ca806f>:0)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass58_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <3037c1046402403280ab8b0782ca806f>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Downgraded to 16.7 and all is fine.

1 Like

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

if (subAsset == null || m_AssetRefObject.SubObjectName == objName &&
                    m_AssetRefObject.SubOjbectType != null
                    && subAsset.GetType().AssemblyQualifiedName == m_AssetRefObject.SubOjbectType.AssemblyQualifiedName)
                    selIndex = i;
1 Like

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

1 Like

Sprites are Addressables nemesis

1 Like

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

1 Like

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. :slight_smile:

1 Like

ffs i have the same error.