- Home /
Using EditorGUI.ObjectField in PropertyDrawer
I would like to use a one-line EditorGUI.ObjectField in my PropertyDrawer, but only get weird-looking results: I can actually select an object in the small field to the right, but I want it to look like with EditorGUILayout.ObjectField (which I cannot use since I am using a PropertyDrawer). Here's my code:
sprite = (Sprite) EditorGUI.ObjectField(new Rect(position.x, currentHeight, position.width, fieldHeight), sprite, typeof(Sprite), false);
currentHeight is a float variable which saves the height of the next element to draw. fieldHeight is a constant float set to 17. Is this a bug or am I doing something wrong?
Why can't you use the EditorGUI.ObjectField in a PropertyDrawer?
You can, and I absolutely can do it for methods, but how to set a object field of the property I'm drawing, with it overriding in prefabs correctly and all? How to set the serialized object back again?
Your answer
![](https://koobas.hobune.stream/wayback/20220612074828im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Property Drawer and Inheritance 0 Answers
CustomPropertyDrawer: foldout issues when switching properties (simulating weak references) 0 Answers
EditorGUI.Foldout -- Cannot interact with contents! 1 Answer
GetPropertyHeight infinite recursion on drawer 1 Answer
EditorGUI.Foldout consumes click so GUI.Button doesnt work when inside of foldout region. 1 Answer