- Home /
Hide the Object Picker in Unity Editor in ObjectField
I'm just asking if there is any possibility to hide the "Object Picker" (The little knob/menu next to an ObjectField in a custom Inspector. I am putting a bunch of these object fields right next to each other, and the object picker is getting in the way.
Answer by dbdenny · Dec 03, 2020 at 07:20 AM
I've got another solution: Ignore the pick result of this object picker, while I still don't know how to hide this button and the pickerwindow, here is the code:
// Register another callback of this object field
myObjectField.RegisterValueChangedCallback(DefaultObjectFieldCallback);
// In this callback, is a trick
private void DefaultAssetFieldCallback(ChangeEvent<UnityEngine.Object> evt) {
// unregister the callback first
myObjectField.UnregisterValueChangedCallback(DefaultAssetFieldCallback);
// trick: set back to the old value
m_ConfigAssetField.value = evt.previousValue;
// register the callback again
myObjectField.RegisterValueChangedCallback(DefaultObjectFieldCallback);
}
Answer by Brodal · Jan 09 at 11:47 AM
Necroing old thread. But I needed to do something similar and found a way to do this by stepping through the ObjectField in the UIToolkit Debugger. The type of the little object selector button is hidden, so we cant really work with the class itself.
This solution is using UIToolkit.
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
// Create ObjectField
var field = new ObjectField(property.displayName);
field.objectType = typeof(MyType);
// Find the little circle button,
// The button is of type ObjectFieldSelector
// which i think is internal which is why we cant simply do
// button.Q<ObjectFieldSelector>
var objectSelector = FindChild(field, "unity-object-field__selector");
// Make the button invisible
objectSelector.visible = false;
return field;
}
// Helper method to find the button using a depth first search
private VisualElement FindChild(VisualElement parent, string ussClass)
{
foreach(var child in parent.Children())
{
if (child.ClassListContains(ussClass))
return child;
var subChild = FindChild(child, ussClass);
if (subChild != null)
return subChild;
}
return null;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612175717im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
EditorGUILayout for GUIStyle 0 Answers
Terrain glitch after editing it 0 Answers
Information box 0 Answers
No solution in Monodevelop 5 Answers