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

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    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);
    5.  
    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.
     
    PlaycorpStudios and janplaehn like this.
  2. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
  3. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    This implementation is quite ugly though...
    Plus, in my case, the "Don't show again" option would be for the Cancel option...

    upload_2022-8-26_11-11-6.png
     
  4. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    I agree, Unity really needs to treat both the OK and Cancel button as valid answers to the prompt, and allow saving of either answer for the session or Machine. As it stands now, if there are multiple items that need a decision, the user can elect to "say yes" to all but if they want to "say no" to all then they will have to shown every prompt.

    The issue is that Unity does not really treat the Dialog messages as a Yes or No (approve or disapprove) question, but rather as a Yes or Cancel operation.

    This is probably not how most developers use it, nor does it seem to be the way that Unity's own developers see it. For example, on the DisplayDialog API page the example shows a Dialog with options "Place" and "Do Not Place". Do Not Place is clearly a defined choice and not a simple cancel operation, so why can it not be saved as the choice for all future prompts for the session or machine?

    If I had to guess I would say this method is just using DisplayDaialogComplex under the hood, which is limited to three options, and that's why this limitation of only being able to save the "OK" choice is there.

    Please add a Dialog that has a checkmark box instead of a button, something where we can say "Remember Choice For Session" or "Remember Choice for Machine"