Your post doesn’t really have anything to do with the thread. The thread is about replicating the MonoScript field that is at the top of all default inspectors.
In any case your inspector code makes little sense, particularly because every repaint, you’re instantiating three new objects (why?). So needless to say the object fields are always going to draw empty, as you’re only ever passing the same new instance through it every repaint.
The point of IMGUI fields is to pass through the CURRENT value, and then assign the return value back if it changes. Passing through the same value every repaint doesn’t make sense.
EDIT:
Looking back it seems you are probably trying to draw regular C# classes, and perhaps want to select a derived type of a base type. Remember that a “script” is actually just a text asset. They don’t actually in and of themselves represent your C# classes, structs, etc.
If you want to draw a regular C# class, with polymorphism, the field needs to be serialized with [SerializeReference]
, and you will need some kind of custom inspector work to allow the selection.
I wrote a generic solution here: