# DisplayDialog

> This method displays a modal dialog.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.0/script-reference/unityeditor.md)
* **Assembly:** UnityEditor

## DisplayDialog(string, string, string, string)

This method displays a modal dialog.

```csharp
public static bool DisplayDialog(string title, string message, string ok, string cancel)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The title of the message box.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The text of the message.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Label displayed on the OK dialog button.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Label displayed on the Cancel dialog button.

### Returns

| Type                                                          | Description                                                             |
| ------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Returns true if the user clicks the OK button. Returns false otherwise. |

### Remarks

Use it for displaying message boxes in the Editor.

ok and cancel are labels to be displayed on the dialog buttons. If cancel is empty (the default), then only one button is displayed. DisplayDialog returns true if ok button is pressed.

For dialog boxes that might be shown repeatedly, consider using an overload of this method that takes a [DialogOptOutDecisionType](/engine/6000.0/script-reference/unityeditor/dialogoptoutdecisiontype.md) as described in the below the code example.

Additional Resources: [EditorUtility.DisplayDialogComplex](/engine/6000.0/script-reference/unityeditor/editorutility/displaydialogcomplex.md) function.

![PlaceSelectionOnSurface (DisplayDialog)](/api/media?file=/engine/6000.0/media/images/PlaceSelectionOnSurface.png)

*Dialog box that shows info on the number of objects to be placed on the surface.*

### Examples

```csharp
// Places the selected Objects on the surface of a terrain.

using UnityEngine;
using UnityEditor;

public class PlaceSelectionOnSurface : ScriptableObject
{
    [MenuItem("Example/Place Selection On Surface")]
    static void CreateWizard()
    {
        Transform[] transforms = Selection.GetTransforms(SelectionMode.Deep |
            SelectionMode.ExcludePrefab | SelectionMode.Editable);

        if (transforms.Length > 0 &&
            EditorUtility.DisplayDialog("Place Selection On Surface?",
                "Are you sure you want to place " + transforms.Length
                + " on the surface?", "Place", "Do Not Place"))
        {
            Undo.RecordObjects(transforms, "Place Selection On Surface");
            foreach (Transform transform in transforms)
            {
                RaycastHit hit;
                if (Physics.Raycast(transform.position, -Vector3.up, out hit))
                {
                    transform.position = hit.point;
                    Vector3 randomized = Random.onUnitSphere;
                    randomized = new Vector3(randomized.x, 0F, randomized.z);
                    transform.rotation = Quaternion.LookRotation(randomized, hit.normal);
                }
            }
        }
    }
}
```

## DisplayDialog(string, string, string, DialogOptOutDecisionType, string)

This method displays a modal dialog that lets the user opt-out of being shown the current dialog box again.

```csharp
public static bool DisplayDialog(string title, string message, string ok, DialogOptOutDecisionType dialogOptOutDecisionType, string dialogOptOutDecisionStorageKey)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The title of the message box.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The text of the message.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Label displayed on the OK dialog button.**** (\[DialogOptOutDecisionType]\(/engine/6000.0/script-reference/unityeditor/dialogoptoutdecisiontype)): The type of opt-out decision a user can make.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The unique key setting to store the decision under.

### Returns

| Type                                                          | Description                                                                                                                                       |
| ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | true if the user clicks the ok button, or previously opted out. Returns false if the user cancels or closes the dialog without making a decision. |

### Remarks

Use this method to display dialog boxes in the Editor that might be shown repeatedly. Choose which DialogOptOutDecisionType to use based on how often you think users encounter this message and how often you want to remind them of it.

If the user opts-out of seeing the dialog box associated with the provided dialogOptOutDecisionStorageKey, Unity doesn't show the dialog box and this method immediately returns true.

ok and cancel are labels displayed on the dialog buttons. If cancel is empty, the button displays as "Cancel". This is the default setting. DisplayDialog returns true if the user presses the ok button.

If the user opts-out of the dialog box, Unity stores this decision. If dialogOptOutDecisionType is set to [DialogOptOutDecisionType.ForThisMachine](/engine/6000.0/script-reference/unityeditor/dialogoptoutdecisiontype/forthismachine.md) Unity stores the decision via [EditorPrefs.SetBool](/engine/6000.0/script-reference/unityeditor/editorprefs/setbool.md). If dialogOptOutDecisionType is set to [DialogOptOutDecisionType.ForThisSession](/engine/6000.0/script-reference/unityeditor/dialogoptoutdecisiontype/forthissession.md) Unity stores the decision via [SessionState.SetBool](/engine/6000.0/script-reference/unityeditor/sessionstate/setbool.md). In both cases Unity stores the decision under the key provided as dialogOptOutDecisionStorageKey.

If you want to the let the user change the decision that is stored in [EditorPrefs](/engine/6000.0/script-reference/unityeditor/editorprefs.md), you can add this to the Editor Preferences with a [SettingsProvider](/engine/6000.0/script-reference/unityeditor/settingsprovider.md).

Use [DialogOptOutDecisionType.ForThisSession](/engine/6000.0/script-reference/unityeditor/dialogoptoutdecisiontype/forthissession.md) to show a dialog before a user performs a destructive action that might lose some of their work. If you think the user might see this dialog too often, you can add an option to the Editor Preferences with a [SettingsProvider](/engine/6000.0/script-reference/unityeditor/settingsprovider.md) by using [EditorPrefs](/engine/6000.0/script-reference/unityeditor/editorprefs.md) and query that setting before showing the dialog.

Additional Resources: [EditorUtility.DisplayDialogComplex](/engine/6000.0/script-reference/unityeditor/editorutility/displaydialogcomplex.md) function.

### Examples

```csharp
// Places the selected Objects on the surface of a terrain.

using UnityEngine;
using UnityEditor;
using UnityEngine.UIElements;

public class PlaceSelectionOnSurface : ScriptableObject
{
    const string placeOnSurfaceDialogDecisionKey = "Example.PlaceOnSurfaceDecision";
    [MenuItem("Example/Place Selection On Surface")]
    static void CreateWizard()
    {
        Transform[] transforms = Selection.GetTransforms(SelectionMode.Deep |
            SelectionMode.ExcludePrefab | SelectionMode.Editable);

        if (transforms.Length > 0 &&
            EditorUtility.DisplayDialog("Place Selection On Surface?",
                "Are you sure you want to place " + transforms.Length
                + " on the surface?", "Place", "Do Not Place", DialogOptOutDecisionType.ForThisMachine, placeOnSurfaceDialogDecisionKey))
        {
            // Register and Undo event so that this action is not only not desctrutive but also easy to revert.
            // Without Undo, DialogOptOutDecisionType.ForThisSession would be a better fiting decision type.
            Undo.RecordObjects(transforms, "Place Selection On Surface");
            foreach (Transform transform in transforms)
            {
                RaycastHit hit;
                if (Physics.Raycast(transform.position, -Vector3.up, out hit))
                {
                    transform.position = hit.point;
                    Vector3 randomized = Random.onUnitSphere;
                    randomized = new Vector3(randomized.x, 0F, randomized.z);
                    transform.rotation = Quaternion.LookRotation(randomized, hit.normal);
                }
            }
        }
    }
}
```

## DisplayDialog(string, string, string, string, DialogOptOutDecisionType, string)

This method displays a modal dialog that lets the user opt-out of being shown the current dialog box again.

```csharp
public static bool DisplayDialog(string title, string message, string ok, string cancel, DialogOptOutDecisionType dialogOptOutDecisionType, string dialogOptOutDecisionStorageKey)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The title of the message box.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The text of the message.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Label displayed on the OK dialog button.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Label displayed on the Cancel dialog button.**** (\[DialogOptOutDecisionType]\(/engine/6000.0/script-reference/unityeditor/dialogoptoutdecisiontype)): The type of opt-out decision a user can make.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The unique key setting to store the decision under.

### Returns

| Type                                                          | Description                                                                                                                                       |
| ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | true if the user clicks the ok button, or previously opted out. Returns false if the user cancels or closes the dialog without making a decision. |

### Remarks

Use this method to display dialog boxes in the Editor that might be shown repeatedly. Choose which DialogOptOutDecisionType to use based on how often you think users encounter this message and how often you want to remind them of it.

If the user opts-out of seeing the dialog box associated with the provided dialogOptOutDecisionStorageKey, Unity doesn't show the dialog box and this method immediately returns true.

ok and cancel are labels displayed on the dialog buttons. If cancel is empty, the button displays as "Cancel". This is the default setting. DisplayDialog returns true if the user presses the ok button.

If the user opts-out of the dialog box, Unity stores this decision. If dialogOptOutDecisionType is set to [DialogOptOutDecisionType.ForThisMachine](/engine/6000.0/script-reference/unityeditor/dialogoptoutdecisiontype/forthismachine.md) Unity stores the decision via [EditorPrefs.SetBool](/engine/6000.0/script-reference/unityeditor/editorprefs/setbool.md). If dialogOptOutDecisionType is set to [DialogOptOutDecisionType.ForThisSession](/engine/6000.0/script-reference/unityeditor/dialogoptoutdecisiontype/forthissession.md) Unity stores the decision via [SessionState.SetBool](/engine/6000.0/script-reference/unityeditor/sessionstate/setbool.md). In both cases Unity stores the decision under the key provided as dialogOptOutDecisionStorageKey.

If you want to the let the user change the decision that is stored in [EditorPrefs](/engine/6000.0/script-reference/unityeditor/editorprefs.md), you can add this to the Editor Preferences with a [SettingsProvider](/engine/6000.0/script-reference/unityeditor/settingsprovider.md).

Use [DialogOptOutDecisionType.ForThisSession](/engine/6000.0/script-reference/unityeditor/dialogoptoutdecisiontype/forthissession.md) to show a dialog before a user performs a destructive action that might lose some of their work. If you think the user might see this dialog too often, you can add an option to the Editor Preferences with a [SettingsProvider](/engine/6000.0/script-reference/unityeditor/settingsprovider.md) by using [EditorPrefs](/engine/6000.0/script-reference/unityeditor/editorprefs.md) and query that setting before showing the dialog.

Additional Resources: [EditorUtility.DisplayDialogComplex](/engine/6000.0/script-reference/unityeditor/editorutility/displaydialogcomplex.md) function.

### Examples

```csharp
// Places the selected Objects on the surface of a terrain.

using UnityEngine;
using UnityEditor;
using UnityEngine.UIElements;

public class PlaceSelectionOnSurface : ScriptableObject
{
    const string placeOnSurfaceDialogDecisionKey = "Example.PlaceOnSurfaceDecision";
    [MenuItem("Example/Place Selection On Surface")]
    static void CreateWizard()
    {
        Transform[] transforms = Selection.GetTransforms(SelectionMode.Deep |
            SelectionMode.ExcludePrefab | SelectionMode.Editable);

        if (transforms.Length > 0 &&
            EditorUtility.DisplayDialog("Place Selection On Surface?",
                "Are you sure you want to place " + transforms.Length
                + " on the surface?", "Place", "Do Not Place", DialogOptOutDecisionType.ForThisMachine, placeOnSurfaceDialogDecisionKey))
        {
            // Register and Undo event so that this action is not only not desctrutive but also easy to revert.
            // Without Undo, DialogOptOutDecisionType.ForThisSession would be a better fiting decision type.
            Undo.RecordObjects(transforms, "Place Selection On Surface");
            foreach (Transform transform in transforms)
            {
                RaycastHit hit;
                if (Physics.Raycast(transform.position, -Vector3.up, out hit))
                {
                    transform.position = hit.point;
                    Vector3 randomized = Random.onUnitSphere;
                    randomized = new Vector3(randomized.x, 0F, randomized.z);
                    transform.rotation = Quaternion.LookRotation(randomized, hit.normal);
                }
            }
        }
    }
}
```
