Custom Editor, GUI.Window and EditorGUILayout.ObjectField not playing nicely

I’ve created a custom EditorWindow. The EditorWindow then spawns a series of GUI.Windows() so that I can easily drag elements within the parent EditorWindow. This works well.

Within each GUI.Window, I enumerate variables for a class, and many times I use either an EditorGUILayout.EnumPopup and EditorGUILayout.ObjectField so that the developer can alter the values for each variable. Here’s where I run into issues. When I click the explore button on the ObjectField, the various assets are displayed in a popup window. When I double click the asset I wish to use for this particular variable, the value does not change in the GUI.Window variable. The only way to change the value is to use DragNDrop from the Project tab.

I’m sure there’s something I’m doing wrong, but I honestly have no idea what that might be. The EnumPopups work just fine, too. Any thoughts?

bump still looking for help on this one

Can you post the code you are using (or at least the context of the part where you display the ObjectField)?

Sure!

First, I make a GUI.Windows() call from the editor OnGUI() function. The GUI.Windows() call references my custom function

Any field within the custom function that is not an EnumPopup has this issue. Here’s an example:

EditorGUILayout.BeginHorizontal(minorItemStyle);
GUILayout.FlexibleSpace();
EditorGUILayout.PrefixLabel("Display Texture");
d.texture = (Texture2D)EditorGUILayout.ObjectField(d.texture, typeof(Texture2D));
EditorGUILayout.EndHorizontal();

anyone have thoughts on this?

Bump bump - still need help with this issue!

Hi,

I can see 2 additional issues in the forum here, all with examples of the above problem. (Which I can confirm occurring in Unity 3.4)

EditorGUILayout.ObjectField fn does not return the selected object from the ObjectSelector editor, when called from within a GUI.Window callback. (or Between BeginWindows() EndWindows() calls inside an EditorWindow).

Does anyone have any more info? Is this a known bug?

Additional threads below:
http://forum.unity3d.com/threads/83165-ObjectField-in-Window-Problem?highlight=ObjectField+EditorWindow
http://forum.unity3d.com/threads/76584-EditorGUI.ObjectField-not-working-properly-in-a-editor-window?highlight=ObjectField+EditorWindow

As a side question, are there any plans to make the ObjectSelector class public? So that it can be called directly, rather than having to create an ObjectField?

Hi,

Did someone get a solution for that ?

Edit : I found that GUILayout.Window() open a new layout considered as “LookLikeInspector”. To get EditorGUILayout methods working and displaying correctly just add :

At the begining of your window !