Search Unity

Showing a second ObjectPicker as soon as the first one closes freezes the editor

Discussion in 'Immediate Mode GUI (IMGUI)' started by SarperS, Dec 27, 2018.

  1. SarperS

    SarperS

    Joined:
    Mar 10, 2009
    Posts:
    824
    In an editor I'm trying to show 2 ObjectPicker 's consecutively, I need the editor to select 2 different object one after the other. The second picker will be shown right after the first one is closed. But this freezes the Unity editor as if it has entered an endless loop. Am I doing something wrong or is this a bug?

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. internal sealed class BugTest : EditorWindow {
    5.     private int _id1;
    6.     private int _id2;
    7.  
    8.     [MenuItem("BUG/Object Picker Freeze Test")]
    9.     private static void Init() {
    10.         var window = GetWindow<BugTest>();
    11.         window.Show();
    12.     }
    13.  
    14.     private void OnGUI() {
    15.         if (GUILayout.Button("Open Object Picker")) {
    16.             _id1 = GUIUtility.GetControlID(FocusType.Passive);
    17.             _id2 = GUIUtility.GetControlID(FocusType.Passive);
    18.  
    19.             EditorGUIUtility.ShowObjectPicker<Transform>(null, true, string.Empty, _id1);
    20.         }
    21.  
    22.         var e = Event.current;
    23.  
    24.         if (e.type == EventType.ExecuteCommand &&
    25.             e.commandName == "ObjectSelectorClosed" &&
    26.             EditorGUIUtility.GetObjectPickerControlID() == _id1) {
    27.  
    28.             e.Use();
    29.  
    30.             Debug.Log("First object picker is closed, now trying to show the second object picker!");
    31.             EditorGUIUtility.ShowObjectPicker<Transform>(null, true, string.Empty, _id2);
    32.         }
    33.     }
    34. }
     
  2. SarperS

    SarperS

    Joined:
    Mar 10, 2009
    Posts:
    824
    If I do these when "ObjectSelectorUpdated" event is raised, it doesn't freeze the editor. "ObjectSelectorClosed" causes the problem. So why is that so?
     
  3. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
    Sounds like a bug to me. I'd try deferring the creation of the second picker to something like the next editor update.
     
  4. SarperS

    SarperS

    Joined:
    Mar 10, 2009
    Posts:
    824
    I've reported it and it was confirmed as a bug. Hopefully it'll get fixed soon.