- Home /
Bool field in CustomPropertyDrawer isn't clickable?
I'm trying to use this function to draw a bool on a custom class of mine:
EditorGUI.PropertyField();
The bool is drawing just fine, and if I click on the label for the bool it'll highlight/select I can press Space to toggle the checkbox/bool, but I can't click on the checkbox itself.
No other inspector GUI stuff I'm doing has this issue.
It almost seems like the checkbox part of the field is outside the hitbox of the field? Anyone got anything on this? Thanks in advance!
Without any code example of what you do that resluts in the thing you describe, I'm afraid that all we can do is guess. So here is my guess ;)
Could it be that you have another (perhaps invisible) component drawn on top? (Or at least another component/rect that can receive your click input)? (Either in the custompropertydrawer or a custom inspector in which 1 or multiple of those properties are drawn).
You could try logging the values of GUIUtility.hotControl and GUIUtility.keyboardControl to see if you can find anything odd there specific to this property.
Also, in case you are not actually working inside a custompropertydrawer where you already have a rect you can use, you could try to use EditorGUILayout.PropertyField() ins$$anonymous$$d. As this class is usefull for when you want to make it look like the rest of the UnityEditor, and Unity takes care of the layout, which requires less code :) and reduces the chance that you have 2 overlapping rectangles that can consume input.
Answer by svendkiloo · Jun 25, 2019 at 09:34 AM
EDIT: Sorry, I only just realised the bit about you being able to toggle the value with space, so I guess the issue isn't the one I describe/solve below. However, it might be worth leaving the answer on here, as it's still relevant to some people (like me) who can't get the bool field to work.
Like @troien mentions, without code we can only guess :) However, I have a different guess, as I experienced the same issue.
If your code looks a bit like this:
EditorGUI.Toggle(rect, isSelected.boolValue);
This would not update the value of isSelected.boolValue, as the Toggle
method returns the new value, rather than write to the parameter (it's passed as value, rather than ref). So you just need to change it to:
isSelected.boolValue = EditorGUI.Toggle(rect, isSelected.boolValue);
He used EditorGUI.PropertyField
, at least that's what he said. PropertyField works on SerializedProperties and does update the value automatically through the SerializedProperty.
As he sea$$anonymous$$gly can actually change the value by pressing space, the assignment can't be an issue.
$$anonymous$$y guess would also be either some overlapping controls so another control "eats" the click event or some other control messes with the hotControl for some reason. Though this $$anonymous$$imalistic question can't be answered.
Answer by nmhild_RP · Jan 14, 2021 at 04:45 AM
If anyone stumbles across this thread, scratching their heads, don't forget to put
serializedObject.ApplyModifiedProperties();
at the bottom of the OnInspectorGUI() method.