How can you show an object's custom inspector when doing nested inspectors?

I have a custom inspector for a class that display some variables, and then has a reference to some other object (say, a ScriptableObject for example). This custom inspector will then also display an inspector for this referenced object by doing the well-known iteration over it:

var serializedObj = new SerializedObject(referencedObject);
var iterator = serializedObj.GetIterator();
if (iterator.NextVisible(true))
{
    do
    {
        EditorGUILayout.PropertyField(iterator);
    }
    while (iterator.NextVisible(false));
}
serializedObj.ApplyModifiedProperties();

Now, say that the referenced object actually had a custom editor script for it. The code above won’t invoke it and instead it will display a default inspector. Is there any way to tell Unity to inspect an object like with PropertyField, except that instead of inspecting a SerializedProperty it will inspect a SerializedObject and therefore respect the custom inspector scripts same as SerializedProperty respects the custom property drawers?

Have you tried Editor.CreateEditor. Calling OnInspectorGUI on the returned Editor will draw it but I’m not sure if the editor is the correct custom editor. You can also specify the wanted Editor type with the editorType parameter.

If, for a given type of object, you provide a custom PropertyDrawer, rather than a Custom Editor script (for your ScriptableObject), this will work as desired.

There MAY be a way to find out if a custom EDITOR for a given type exists, and invoke that, but I’m certain it will require access unity internal stuff, via reflection. (I have one for PropertyDrawers now). I’ll look into this. (update: no luck so far)