Search Unity

EditorUtility.DisplayDialog spawns the dialog behind the editor window on Mac

Discussion in 'Immediate Mode GUI (IMGUI)' started by Qvist, Dec 1, 2017.

  1. Qvist

    Qvist

    Joined:
    Dec 2, 2010
    Posts:
    76
    Hi,

    I'm having an issue with an editor window + dialog on a Mac - note that it works as it should on a Windows PC.
    The purpose of the editor window is to set some settings and based on that generate a prefab. Right after PrefabUtility.CreatePrefab, I call EditorUtility.DisplayDialog, but it is spawned behind the EditorWindow. It should always spawn on top of existing windows.

    Anyone knows how to solve this? As far as I know, there's no way to force the dialog to be displayed on top, because it should do that by default?

    Thanks
     
  2. shawn

    shawn

    Unity Technologies

    Joined:
    Aug 4, 2007
    Posts:
    552
    The behavior you're describing is quite odd. I agree that DisplayDialog should always pop-up a modal dialog in front. Do you have some example code to look at?
     
  3. Qvist

    Qvist

    Joined:
    Dec 2, 2010
    Posts:
    76
    Alright, just created a quick test project with the last part of the editor window, and now Unity is quitting unexpectedly (when the script is run). Still only happens on the mac.
    @shawn

    Code (CSharp):
    1. public class Test : EditorWindow {
    2.  
    3.     [MenuItem("Test/Show")]
    4.     static void ShowWindow()
    5.     {
    6.         GetWindow<Test>(true, "Test Setup");
    7.     }
    8.  
    9.     private void OnGUI()
    10.     {
    11.         GameObject testGameObject = new GameObject("Test");
    12.         PrefabUtility.CreatePrefab("Assets/Prefabs/test.prefab",
    13.             testGameObject);
    14.         DestroyImmediate(testGameObject);
    15.         if (EditorUtility.DisplayDialog("Setup completed",
    16.             "Place the test prefab in your scene", "Ok"))
    17.         {
    18.             Close();
    19.         }
    20.     }
    21. }
    Unity version: 2017.2.0f3

    The error log is attached.
     

    Attached Files:

  4. shawn

    shawn

    Unity Technologies

    Joined:
    Aug 4, 2007
    Posts:
    552
    I had to change the script slightly to get the EditorWindow to reliably show up. The script you provided immediately created the prefab in the first OnGUI call, which never gave the window a chance to repaint properly. Also fixed the path so that it worked in an empty project without a Prefabs folder.

    Anyways, after doing that I was unable to recreate the behavior that you described using 2017.2.0f3. Let me know if there's anything else needed to reproduce it.

    DisplayDialog.gif

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. public class Test : EditorWindow {
    5.     [MenuItem("Test/Show")]
    6.     static void ShowWindow()
    7.     {
    8.         GetWindow<Test>(true, "Test Setup");
    9.     }
    10.     private void OnGUI()
    11.     {
    12.         if (GUILayout.Button("Create Prefab"))
    13.         {
    14.             GameObject testGameObject = new GameObject("Test");
    15.             PrefabUtility.CreatePrefab("Assets/test.prefab",
    16.                 testGameObject);
    17.             DestroyImmediate(testGameObject);
    18.             if (EditorUtility.DisplayDialog("Setup completed",
    19.                 "Place the test prefab in your scene", "Ok"))
    20.             {
    21.                 Close();
    22.             }
    23.         }
    24.     }
    25. }
    26.  
     
  5. Qvist

    Qvist

    Joined:
    Dec 2, 2010
    Posts:
    76
    @shawn Yeah, already had the Prefabs folder in the test project - sorry about that.
    Found out that it wasn't the prefab thing that caused the issue, but having another dialog right before. In the real thing, we have a number of steps, and asks the user to accept before progressing to the next step.
    See the example in the new test project below.
    test (1).gif

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEngine;
    5.  
    6. public class Test : EditorWindow {
    7.  
    8.     [MenuItem("Test/Show")]
    9.     public static void ShowWindow()
    10.     {
    11.         GetWindow<Test>(true, "Test Setup");
    12.     }
    13.  
    14.     private void OnGUI()
    15.     {
    16.         if (GUILayout.Button("Create prefab"))
    17.         {
    18.  
    19.             if (EditorUtility.DisplayDialog("Are you sure",
    20.                 "..", "Yes", "No"))
    21.             {
    22.                 GameObject testGameObject = new GameObject("Test");
    23.                 PrefabUtility.CreatePrefab("Assets/Prefabs/test.prefab",
    24.                     testGameObject);
    25.                 DestroyImmediate(testGameObject);
    26.                 if (EditorUtility.DisplayDialog("Setup completed",
    27.                     "Place the test prefab in your scene", "Ok"))
    28.                 {
    29.                     Close();
    30.                 }
    31.             }
    32.         }
    33.     }
    34. }
    35.  
    Thanks!
     
  6. shawn

    shawn

    Unity Technologies

    Joined:
    Aug 4, 2007
    Posts:
    552
    Ah, I see! Good catch, I'll forward this on.

    Unfortunately, I don't think there's any workaround really. Other than changing the flow so that a dialog doesn't spawn another.
     
  7. Qvist

    Qvist

    Joined:
    Dec 2, 2010
    Posts:
    76
    Ah okay. Fun thing is that it works on Windows, but yeah, I'll just change the flow for now.

    Thanks for your time!
     
  8. shawn

    shawn

    Unity Technologies

    Joined:
    Aug 4, 2007
    Posts:
    552
    Quick question, which version of macOS are you using?
     
  9. Qvist

    Qvist

    Joined:
    Dec 2, 2010
    Posts:
    76
    All specs should be in the error log i sent. But it's Sierra, ver. 10.12.6.