Search Unity

Property drawers in DLL cause errors

Discussion in 'Immediate Mode GUI (IMGUI)' started by TehGM, Aug 28, 2016.

  1. TehGM

    TehGM

    Joined:
    Nov 15, 2013
    Posts:
    89
    Hi.
    I have a simple property drawer code put in DLL.
    Code (csharp):
    1. [CustomPropertyDrawer(typeof(ToggleButtonAttribute))]
    2. public class ToggleButtonAttributeDrawer : PropertyDrawer
    3. {
    4.    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    5.    {
    6.       ToggleButtonAttribute attr = attribute as ToggleButtonAttribute;
    7.  
    8.       bool value = property.boolValue;
    9.       string nameString = attr.NameString == null ? label.text : attr.NameString;
    10.       string valueString = value ? attr.TrueString : attr.FalseString;
    11.  
    12.       Rect btnPos = EditorGUI.PrefixLabel(position, new GUIContent(nameString));
    13.       if (GUI.Button(btnPos, valueString))
    14.          property.boolValue = !value;
    15.    }
    16. }
    At first it worked fine - I dropped DLL in Editor folder and my button was drawn.
    Then at some point I included reference to GUILayout class instead of GUI. I started getting 2 errors.

    I reverted changes to the code above, yet the error still happens whenever DLL is in project.

    When I delete it, and place the exact same code as a script, it works properly. However starts failing when I drop DLL again - even when I comment out the attributes so the Drawers are not used - DLL just needs to be in the project. Errors stop when there's no more CustomPropertyDrawer attribute used in the library code - all else fails - even if the property drawer has no OnGUI overriden.


    Adding a script in Unity itself as a wrapper
    Code (csharp):
    1. [CustomPropertyDrawer(typeof(ToggleButtonAttribute))]
    2. public class ToggleButtonWrapper : ToggleButtonAttributeDrawer { }
    seems to make issue go away, however I find it unnecessary hassle and hope there's a way to make it work directly from DLL.
     
    Last edited: Aug 28, 2016
  2. shawn

    shawn

    Unity Technologies

    Joined:
    Aug 4, 2007
    Posts:
    552
    Interesting... sounds like you might have encountered a bug here. Could you report a bug with a project and dll in question? After reporting, post the case number here and we can dig into it.
     
  3. TehGM

    TehGM

    Joined:
    Nov 15, 2013
    Posts:
    89
    Yes, I'll try to strip the project down a bit soon so it's smaller and less messy and then send you the files.
     
  4. shawn

    shawn

    Unity Technologies

    Joined:
    Aug 4, 2007
    Posts:
    552
    Thanks!
     
  5. TehGM

    TehGM

    Joined:
    Nov 15, 2013
    Posts:
    89
    First of all, sorry for (very) late reply now. I got really busy with other things.
    I copied project folder and started deleting things today - however, I noticed there's no error now. I checked the main, unstripped project too, restarted editor as well, and there's no error.
    Should I send the smaller one with deleted things anyway for more investigation? I will keep eye out for the same issue happening again and will send asap then, can't promise how fast will this happen, though.