Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. We're excited to be bringing you the newest Unity features, news, demos, and we've even got some special guests from some of the industry’s most storied franchises. Set a reminder to tune in on YouTube here
    Dismiss Notice
  3. Unity 2018.3 is now released.
    Dismiss Notice

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

Discussion in 'Extensions & OnGUI' started by Sarper-Soher, Dec 27, 2018.

  1. Sarper-Soher

    Sarper-Soher

    Joined:
    Mar 10, 2009
    Posts:
    799
    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. Sarper-Soher

    Sarper-Soher

    Joined:
    Mar 10, 2009
    Posts:
    799
    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:
    570
    Sounds like a bug to me. I'd try deferring the creation of the second picker to something like the next editor update.
     
  4. Sarper-Soher

    Sarper-Soher

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