AddressableReference PropertyField is not renameable in CustomPropertyDrawer

Hi!

I’m trying to make a CustomPropertyDrawer, that contains Addressable AssetReference fields. when I try to set the GuiContent to a custom text or none, the AssetReference field name persists.

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
    Rect propertyRect = new Rect(position.x, position.y + _propertyHeightPlusGap, position.width, _propertyHeight);
    EditorGUI.BeginProperty(position, label, property);
    EditorGUI.PropertyField(propertyRect, property.FindPropertyRelative("_assetReference"), new GUIContent("Field"));
    EditorGUI.EndProperty();
}

I would expect the GUIContent parameter to work as it does with other serialized fields as well. Now it just prints “_assetReference” regardless of the value in GUIContent parameter.

  • P

Thanks for the post, it’s a bug we have in our backlog and just haven’t gotten to yet. We’ll give it a +1 based on this post.

1 Like

Can confirm this is still happening on 2019.4.4f1

[System.Serializable]
public class ScreenStatePrefabPair
{
    public ScreenStateType m_state;
    public AssetReference m_asset;
}
[CustomPropertyDrawer(typeof(ScreenStatePrefabPair))]
public class ScreenStatePrefabPairDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);
        float halfWidth = position.width / 2.0f;
        Rect propertyRect = position;
        propertyRect.width = halfWidth;
        EditorGUI.PropertyField(propertyRect, property.FindPropertyRelative("m_state"), GUIContent.none);
        propertyRect.x += halfWidth;
        EditorGUI.PropertyField(propertyRect, property.FindPropertyRelative("m_asset"), GUIContent.none);
        EditorGUI.EndProperty();
    }
}
public class TestPair : MonoBehaviour
{
    [SerializeField] private ScreenStatePrefabPair m_pair;
}

What is really interesting is that the variable name of the AssetReference (m_asset) in this case will be drawn everywhere in the editor.