Search Unity

AddressableReference PropertyField is not renameable in CustomPropertyDrawer

Discussion in 'Addressables' started by Pasketi, Oct 14, 2019.

  1. Pasketi

    Pasketi

    Joined:
    Sep 27, 2019
    Posts:
    3
    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.

    Code (CSharp):
    1. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    2. {
    3.     Rect propertyRect = new Rect(position.x, position.y + _propertyHeightPlusGap, position.width, _propertyHeight);
    4.     EditorGUI.BeginProperty(position, label, property);
    5.     EditorGUI.PropertyField(propertyRect, property.FindPropertyRelative("_assetReference"), new GUIContent("Field"));
    6.     EditorGUI.EndProperty();
    7. }
    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
     
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    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.
     
    Pasketi likes this.
  3. WrGraban

    WrGraban

    Joined:
    Jul 15, 2012
    Posts:
    2
    Can confirm this is still happening on 2019.4.4f1

    Code (CSharp):
    1.  
    2. [System.Serializable]
    3. public class ScreenStatePrefabPair
    4. {
    5.     public ScreenStateType m_state;
    6.     public AssetReference m_asset;
    7. }
    Code (CSharp):
    1.  
    2. [CustomPropertyDrawer(typeof(ScreenStatePrefabPair))]
    3. public class ScreenStatePrefabPairDrawer : PropertyDrawer
    4. {
    5.     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    6.     {
    7.         EditorGUI.BeginProperty(position, label, property);
    8.         float halfWidth = position.width / 2.0f;
    9.         Rect propertyRect = position;
    10.         propertyRect.width = halfWidth;
    11.         EditorGUI.PropertyField(propertyRect, property.FindPropertyRelative("m_state"), GUIContent.none);
    12.         propertyRect.x += halfWidth;
    13.         EditorGUI.PropertyField(propertyRect, property.FindPropertyRelative("m_asset"), GUIContent.none);
    14.         EditorGUI.EndProperty();
    15.     }
    16. }
    17.  
    Code (CSharp):
    1.  
    2. public class TestPair : MonoBehaviour
    3. {
    4.     [SerializeField] private ScreenStatePrefabPair m_pair;
    5. }
    6.  
    What is really interesting is that the variable name of the AssetReference (m_asset) in this case will be drawn everywhere in the editor.