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

Custom PropertyDrawer is not called

Discussion in 'Editor & General Support' started by tribaleur, Feb 18, 2020.

  1. tribaleur

    tribaleur

    Joined:
    Jan 19, 2017
    Posts:
    34
    Hello,

    I don't understand why my custom PropertyDrawer is not called from my custom Editor.

    Here my property declaration :
    Code (CSharp):
    1. [SerializeField]
    2.     private List<SpellEffect>    _spellsEffects;
    Here how the propertyDrawer is called in my custom Editor :
    Code (CSharp):
    1. // --- SpellsEffects ---
    2.         Debug.Log("Call property drawer");
    3.         SerializedProperty se = this.serializedObject.FindProperty("_spellsEffects"); // I checked in debug mod : everything is OK at this point.
    4.         EditorGUILayout.PropertyField(se, true);
    Here my propertyDrawer definition :
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using UnityEditorInternal;
    4. using System.Collections.Generic;
    5.  
    6. [CustomPropertyDrawer(typeof(List<SpellEffect>))]
    7. public class Drawer_object : PropertyDrawer {
    8.     //_____ CONSTRUCTOR _________________________________________________________
    9.     public Drawer_object () : base() {
    10.         Debug.Log("Init PropertyDrawer");
    11.     }
    12.  
    13.     ~Drawer_object () {
    14.         Debug.Log("Destructor PropertyDrawer");
    15.     }
    16.  
    17.     //_____ TRIGGER _____________________________________________________________
    18.     public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
    19.         Debug.Log("ON GUI PropertyDrawer");
    20.     }
    21. }
    Here my consol log :
    upload_2020-2-18_18-19-0.png

    As you can see the PropertyDrawer is never called. Do you have an idea why ?

    Thanks for your help.
     
  2. SirIntruder

    SirIntruder

    Joined:
    Aug 16, 2013
    Posts:
    49
    I think it should be [CustomPropertyDrawer(typeof(SpellEffect))].
    Property drawers for list fields are not done on the list property itself, it's one property drawer call per each list element.
    Also make sure SpellEffect has System.Serializable attribute
     
  3. tribaleur

    tribaleur

    Joined:
    Jan 19, 2017
    Posts:
    34
    Hello,

    Thanks for your reply. It looks like you are true : https://forum.unity.com/threads/pro...-inspector-customization.150337/#post-1031443
    It's an old post but we can't do propertyDrawer for List or Array themself.

    A solution could be to wrap the list inside a custom classe, but the downside is that this class won't be serialized as an array/List by unity.
    Thanks for your help, i have to find an other way to do that.