Call inspector on custom window editor

Hi there, here is the thing: in my scene i have several objects and each one of them have like 5 or 6 script components, and each one has several config options. So for organization’s sake i decided to make a custom window that shows a node-like view of your selected gameobject, and it displays in a 2d view all the components that conform that game object ( and how they interact with each other, with arrows). When you select one component in that 2d view, a second inspector windows comes in showing you only the component that you selected so you can modify their options.

The problem is how to represent that inspector-like window, i’ve been searching alot but with no result. And on top of this, some scripts have a custom inspector script so that’s why i’m trying to call an inspector window here. Does anyone know if this kind of thing is possible ? otherwise i would like to know if there is a better or different solution to this organization thing. Of course its not critical, but would help alot having one of this. Cheers

4 Answers

4

Editor editor = Editor.CreateEditor( gameObject );
editor.DrawDefaultInspector();

I don’t know how to draw it in specified area, but it works for plain drawing inside EditorWindow and even inside custom layout areas.

to draw it in specified area, use this: Rect myRect = new Rect(); myRect.center = Vector2.one*200; GUILayout.BeginArea(myRect); myEditor.DrawDefaultInspector(); //confines the editor to the specified rectangle GUILayout.EndArea();

Based upon @MaxEden 's answer this is how to do it with a custom inspector rather than the Unity default one:

AchievementEditor editor = (AchievementEditor)Editor.CreateEditor(achievement.objectReferenceValue, typeof(AchievementEditor));
            editor.OnInspectorGUI();

Where AchievementEditor is the name of my custom editor.

There’s not really a way to call an inspector, unfortunately. You’d have to provide a function for each component, even the ones you’d rather have default inspector on.

If you’re wondering about creating an actual editor window, you can use EditorWindow to do that.

yes that's actually what im doing, inside that editor window i was trying to display that 2d space with the little nodes representing the components of the object. it's such a shame that you don't have a little more freedom for controlling the inspector. Btw do you know a way for at least "call" the inspector window and dock it to the new custom window you just created ? (when using EditorWindow.GetWindow(typeof(WindowToDock));

This is more of a conceptual suggestion but what if you just added a new inspector tab and then saved the layout? Let unity remember that you want to have an inspector there(instead of hard coding it). Also, look into Bolt. It’s a node-based programming asset purchased and released by Unity. It costs a pretty penny but I think its right up your alley and would let you get deeper into your projects.