Adding OnInspectorGUI to built-in components

Is it possible to either call or extend another custom Inspector defined for built-in components? I tend to assume it isn’t possible because of the way OnInspectorGUI works, not to mention C# itself, but I want to be sure I haven’t overlooked something.

I wanted to expose the aspect ratio property of all Camera components. I’m using several render textures and their cameras should be 1:1 but it seemed sort of stupid and wasteful to deploy code for that kind of thing at runtime rather than serializing it from the editor.

I wrote a simple OnInspectorGUI to do just that, but noticed calling DrawDefaultInspector() uses the generic Editor inspector – for example, Field of View becomes just an input box rather than a range-limited slider.

Alternately, is there maybe some way in an editor extension to intercept the serialization of a particular component and update it that way?

I know it’s relatively minor as wasteful processes go; this is more about curiosity now than micro-optimization.

  1. You can create your own inspector for built-in components.
  2. Overriding built-in inspectors (e.g: Unity’s default inspectors) is a bit trickier, but also possible. See my blog post here: http://www.tallior.com/extending-unity-inspectors/

What you describe happens because Unity has already defined an inspector for that component; DrawDefaultInspector uses the default behaviour from the Editor class, not from the inspector that you’re used to using.

Check out my link above to see how you can still achieve what you need :slight_smile:

1 Like

Thanks. I’d probably have to be pretty desperate to resort to grabbing private objects via reflection!

Well, there’s no other good way of doing that. All of the default inspectors are internal (to the UnityEditor.dll) so you cannot extend them in any way.

Yeah that’s pretty much what I figured, but thought I’d ask just in case.