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

"type is not a supported int value" on a boolean in a property drawer

Discussion in 'Scripting' started by Saticmotion, Feb 6, 2019.

  1. Saticmotion

    Saticmotion

    Joined:
    Aug 27, 2014
    Posts:
    15
    I'm making a custom property drawer, where you can edit 3 booleans (select the axes of the object that are allowed to be rescaled). Despite the drawer and (de)serializing working, I still keep getting "type is not a supported int value" errors. I've marked the exact locations in the code snippet below. Seems weird that I get errors about ints in a bool. What's going on, and how do I stop the error from happening?

    Code (CSharp):
    1.  
    2.     [Serializable]
    3.     public class AxisSelector
    4.     {
    5.         public bool x;
    6.         public bool y;
    7.         public bool z;
    8.     }
    9.  
    10.     [CustomPropertyDrawer(typeof(AxisSelector)), CanEditMultipleObjects]
    11.     public class AxisSelectorDrawer : PropertyDrawer
    12.     {
    13.         public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    14.         {
    15.             return 2 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing);
    16.         }
    17.  
    18.         public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    19.         {
    20.             EditorGUI.BeginProperty(position, label, property);
    21.             position.y += 9;
    22.  
    23.             EditorGUI.LabelField(new Rect(position.x, position.y, position.width * .4f, 20), "Select resizable axes");
    24.  
    25.             EditorGUIUtility.labelWidth = 14;
    26.             var rect = new Rect(position.x + position.width * .38f, position.y, 30, 16);
    27.  
    28.             var prop = property.FindPropertyRelative("x");
    29.             //type is not a supported int value
    30.             property.boolValue = EditorGUI.PropertyField(rect, prop, new GUIContent("X"));
    31.             rect.x += 30;
    32.  
    33.             prop = property.FindPropertyRelative("y");
    34.             //type is not a supported int value
    35.             property.boolValue = EditorGUI.PropertyField(rect, prop, new GUIContent("Y"));
    36.             rect.x += 30;
    37.  
    38.             prop = property.FindPropertyRelative("z");
    39.             //type is not a supported int value
    40.             property.boolValue = EditorGUI.PropertyField(rect, prop, new GUIContent("Z"));
    41.            
    42.             EditorGUI.EndProperty();
    43.         }
    44.     }
     
  2. Saticmotion

    Saticmotion

    Joined:
    Aug 27, 2014
    Posts:
    15
    I also created an empty project, with just the code above:
     

    Attached Files:

  3. DanielK2

    DanielK2

    Joined:
    Jul 17, 2017
    Posts:
    10
    I just got the same error but couldn't find anything online so here are my findings on it. I had the same question mark: Why is it asking for an "int" value while I'm calling the ".boolValue" of the serializedProperty? I guess the error message is wrong or at least pointing you in the wrong direction. It seems that the actual meaning of this error is something like "You think that your serializedProperty where you access the '.boolValue ' represents a 'serialized bool value', but it doesn't. It represents something else."

    That pointed me in the right direction and I could solve my problem (using Unity 2019.4 btw). In your case it may be the missing "[SerializeField]" in front of the bool fields inside inside the AxisSelector class.
     
  4. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,572
    Well, the error is pretty obvious. "property" is the serialized property that represents the "AxisSelector" field. "prop" is the nested / child property that represents one of the boolean fields. This part makes no sense:

    Code (CSharp):
    1. property.boolValue =
    "property" is not a boolean property as we just established. So setting that property to a boolean value just makes no sense. Apart from that EditorGUI.PropertyField does not return the boolean value of a boolean property but returns if the property that is drawn has further child properties. So assigning that value to a property also makes no sense.
     
  5. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,572
    Well, wrong is not the right word here. Technically any simple integral type is just represented as an integer internally on the C++ side. So no matter if it's a byte, short, int or bool they all are just a simple primitive type.

    No, that's not necessary if the field is public. The issue is the wrong usage of the PropertyField method. You should completely ignore the return value. When in doubt, read the manual.