EditorGUILayout.Popup in CustomPropertyDrawer

How can I create a simple popup drawer please?

Error:
ArgumentException: Getting control 9’s position in a group with only 9 controls when doing Repaint
Aborting

DataTest.cs

[Serializable]
public class DataTest
{
	public int test0;
}

Editor/DataTestEditor.cs

[CustomPropertyDrawer(typeof(DataTest))]
public class DataTestEditor : PropertyDrawer
{
	private readonly string[] _names0 = { "a", "b", "c" };
	public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
	{
		var property0 = property.FindPropertyRelative("test0");
		property0.intValue = EditorGUILayout.Popup("test0", property0.intValue, _names0, EditorStyles.popup);
	}
	public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
	{
		return 16f;
	}
}

Thank you.

You can’t use GUILayout (or EditorGUILayout) methods in property drawers’ OnGUI. Use EditorGUI or GUI instead. For popups, EditorGUI.Popup.

I wrote a gui wrapper that lets you use GUI methods in a GUILayout-fashion I plan to put it soon on the forums. This lets you avoid having to deal with GUI directly and manually positioning stuff via rects, etc.

Vote for the feature if you want it.

There’s also this workaround I think you should know about.