Search Unity

Feedback Improve EditorUtility.DisplayDialog by supporting simple "don't ask again" option(s)

Discussion in 'Editor & General Support' started by Xarbrough, Dec 4, 2019.

  1. Xarbrough


    Dec 11, 2014
    I frequently use EditorUtility.DisplayDialog and EditorUtility.DisplayDialogComplex for custom editor tools, which is a nice way of handling certain errors or getting feedback from the user for critical actions.

    Designing such messages is a hard task when trying to accommodate for different users, so most of the time it makes sense to provide at least a single option to disable a dialog popup in the future. This is in-line with how operating systems and most programs handle warnings or safety measures such as "Are you sure you want to delete these files?". It makes sense to prompt new users with important messages, but advanced users most likely want to disable such a popup.

    Both Windows and Mac provide nice native UI to set such options directly in the modal dialogs, which Unity uses under the hood when I call EditorUtility.DisplayDialog. For example:

    upload_2019-12-4_11-3-39.png upload_2019-12-4_11-6-13.png

    From my experience I would say it would suffice to expose only a single optional bool toggle per dialog for most use cases. As a developer, I would like to provide my own text and handling of the toggle control value. I would imagine the API something like this:

    Code (CSharp):
    1. [MenuItem("Utility/Delete Evil Files")]
    2. public static void RequestDeleteEvilFiles()
    3. {
    4.     bool showAgainOption = EditorPrefs.GetBool("MyTool/ShowAgain", true);
    6.     if (EditorUtility.DisplayDialogWithOption(
    7.         title: "Delete Evil Files",
    8.         message: "Do you want to delete all evil files on the system?",
    9.         confirm: "Yes",
    10.         reject: "No",
    11.         optionText: "Show this message again.",
    12.         optionValue: showAgainOption,
    13.         out bool optionResult
    14.         ))
    15.     {
    16.         EditorPrefs.SetBool("MyTool/ShowAgain", optionResult);
    17.         DeleleteEvilFiles();
    18.     }
    19. }
    Or, if future enhancements in this are of the Unity API are planned, it would make sense to return a more complex result struct that contains information about user selected options and pressed buttons.

    PS: As a limited workaround today, it is possible to use DisplayDialogComplex with three buttons "Yes", "Yes, Don't Ask Again" and "No" to implement the basic functionality ourselves, but this rather ugly and not in-line with operating system guidelines. It's hard to fit the text onto a nice looking button and it only supports saving the the option for either yes or no but not for both.