Is it possible to re-use custom propertyDrawer inside customEditor ?

Hello guys,

Simple question, is there a way inside a Custom Inspector to call/use a specific PropertyDrawer to manage the display of a property ? I ask this, because sometimes I have to re-write code that really looks the same when I want a custom inspector for a class that has a property for which I have already wrote a PropertyDrawer.

Thanks

Yes you can!

You have to get the field as a serialized property, then draw it using editorguilayout.propertyField (property)

It’s a bit of a faff to do this iirc (I don’t have code with me ) if the field belongs to the custom editor. Do you have any sample code to go off, so I can give you a more defined solution?

Thanks for the tips. I will try that out and see what happens :slight_smile:

Hi,

I was able to find this snippet of code which may help you.

    public class MyScriptEditor : Editor
    {
        public override void OnInspectorGUI()
        {


  var it = serializedObject.GetIterator();
            EditorGUI.BeginChangeCheck();

            bool Enter = true;
            while (it.NextVisible(Enter))
            {

                if (  it.name == "Robot")
                {
                    EditorGUILayout.ObjectField(it);
                }
                else
                    Enter = EditorGUILayout.PropertyField(it);

            }

            if (EditorGUI.EndChangeCheck())
            {
                so.ApplyModifiedProperties();

            }
}

This pretty much draws the inspector as default, except for my field labelled Robot

I have just made a quick test and it works. Thanks !