Search Unity

Unity 4.2 and Property Drawers

Discussion in 'Editor & General Support' started by MatthewLeeFarmer, Jul 24, 2013.

  1. MatthewLeeFarmer

    MatthewLeeFarmer

    Joined:
    Jul 31, 2012
    Posts:
    14
    Good Day,

    I've been having some difficulty upgrading from 4.1.5 to 4.2.

    Last week, I built several custom classes, each with their own custom property drawer. This was done in Unity 4.1.5. The steps I took could be found here under (Writing a PropertyDrawer for a custom Serializable Class):
    http://blogs.unity3d.com/2012/09/07/property-drawers-in-unity-4/

    When we updated to Unity 4.2, all of the custom property drawers were no longer being used. It's as if we commented out the code, but hadn't. The exception being on properties of a class derived from monobehavour.

    So this works:
    Code (csharp):
    1.  
    2. public class Monster : MonoBehaviour
    3. {
    4.     [Range (0, 100)]
    5.     public float Speed = 0.0f;
    6. }
    7.  
    But this doesn't:
    Code (csharp):
    1.  
    2. [System.Serializable]
    3. public class MonsterSettings
    4. {
    5.     [Range (0, 100)]
    6.     public float Speed = 0.0f;
    7. }
    8.  
    Has anyone had this issue as well? Any work arounds?
    Thank you!
     
  2. Razieln64

    Razieln64

    Joined:
    May 3, 2008
    Posts:
    129
    Hi,

    I get the same behaviour and also a great slowdown. When I have a class with more than 3 property drawers, Unity slows down to a crawl making it impossible to use. I think this is a regression. I had top speed in 4.1.5.

    I tried batching the linq queries (they update at every 10 seconds or more) that my property drawers use and it is still awfully slow.

    Also I had property drawer attributes inside a serializable class that were working fine before the update. Now it does nothing. It's just broken.

    Also if you use property drawer attributes on an serialized property the attribute is propagated to them if you use EditorGUI.PropertyField. This means you cannot call EditorGUI.PropertyField on the contained properties since it will be the container's property drawer's onGUI that will be called and not the default one.

    Before 4.2 this was working:

    Code (csharp):
    1.  
    2. [System.Serializable]
    3. public class MySerializedClass
    4. {
    5.        [SerializeField]
    6.        private int m_index;
    7.  
    8.        [Range(0f,1f)]
    9.        [SerializeField]
    10.        private float m_slider;
    11. }
    12.  
    13. public class Test : MonoBehaviour
    14. {
    15.       [SomePropertyDrawerAttribute("Hi")]
    16.       MySerializedClass myclass;
    17. }
    18.  
    19. [CustomPropertyDrawer(typeof(SomePropertyDrawerAttribute))]
    20. public class SomePropertyDrawer : PropertyDrawer {
    21.  
    22.     public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
    23.     {
    24.         var attribute = (SomePropertyDrawerAttribute)this.attribute;
    25.        
    26.                // This will display Hi, as declared in the attribute constructor , but you could use it for something else
    27.                Debug.Log(attribute.message);
    28.  
    29.         var indexValueProp = property.FindPropertyRelative("m_index");
    30.         var sliderValueProp = property.FindPropertyRelative("m_slider");
    31.  
    32.         var halfHeight = position.height * 0.5f;
    33.                
    34.                string[] names = new string[] {"Bob", "Roger", "Max"};
    35.  
    36.                indexValueProp.intValue = EditorGUI.Popup(new Rect(position.x, position.y, position.width, halfHeight),label.text,indexValueProp.intValue, names);
    37.  
    38.                 // we just call the usual gui controls that will display the range slider since it has the range attribute
    39.         EditorGUI.PropertyField(new Rect(position.x, position.y+halfHeight, position.width, halfHeight),sliderValueProp, new GUIContent("Slider"));
    40.     }
    41.  
    42.     public override float GetPropertyHeight (SerializedProperty property, GUIContent label)
    43.     {
    44.         var indexValuePropHeight = EditorGUI.GetPropertyHeight(property.FindPropertyRelative("m_index"));
    45.         var sliderValuePropHeight = EditorGUI.GetPropertyHeight(property.FindPropertyRelative("m_slider"));
    46.         return indexValuePropHeight + sliderValuePropHeight;
    47.     }
    48. }
    49.  
    50.  
    The code above doesn't work in 4.2 any more. In 4.2 SomePropertyDrawer.OnGui gets called with m_slider property as a parameter instead of displaying the slider.

    It used to work just fine in 4.1.5.

    It's funny, there was a single change about property drawers in 4.2 release notes and it just broke this feature.

    Please make it work as in 4.1.5.

    Thank you.
     
    Last edited: Jul 24, 2013
  3. Vilmantas

    Vilmantas

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    29
    HI,

    we are ware about this issue, will fix it soon.

    Kind regards,
    Vilmantas,
    Unity Technologies
     
  4. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Hi, this regression has been fixed and will be released ASAP in a point update.
     
  5. Razieln64

    Razieln64

    Joined:
    May 3, 2008
    Posts:
    129
    Thank you for responding quickly. I'm looking forward to the update. :)
     
  6. Dino-Dini

    Dino-Dini

    Joined:
    May 26, 2013
    Posts:
    4
    I have just upgraded to 4.2 and now cannot use my custom editor tools for this reason. Do you have an ETA for a fix, as it is holding me up. Are we talking a day, a week or a month?

    Cheers!
     
  7. Dino-Dini

    Dino-Dini

    Joined:
    May 26, 2013
    Posts:
    4
    Update: In my case the drawer appeared to be gone, but I noticed the first control was there. It turned out that

    EditorGUI.GetPropertyHeight( ..... );

    Is returning bad information (a much bigger value than it should). I have worked around the problem for now by hard coding the height of the controls.
     
  8. Razieln64

    Razieln64

    Joined:
    May 3, 2008
    Posts:
    129
    Ok just to let you know that I tried 4.2.1 RC1 and it was still slow. I cached all my linq queries so they would only refresh once every second and it is working fine now.

    I was using some UnityEditorInternal stuff to get info from mecanim animator controllers. I changed my code from 4.1.5 since it would not compile in 4.2 anymore. This introduced the major slowdown. The mecanim libraries refactoring made it slow since I had to create my own data structures once for every property drawer using an animator controller as its source.

    Now with my linq fix it is faster or the same as in 4.1.5.
     
    Last edited: Aug 7, 2013