Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


DisplayDialog

This method displays a modal dialog.
Read time 6 minutesLast updated 8 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor.CoreModule

DisplayDialog(string, string, string, string)

This method displays a modal dialog.
public static bool DisplayDialog(string title, string message, string ok, string cancel)

Parameters

title

The title of the dialog box. If left null, defaults to "Unity".

message

The text of the message.

Label displayed on the OK dialog button.

cancel

Label displayed on the Cancel dialog button.

Returns

Type

Description

boolReturns
true
if the user clicks the OK button. Returns
false
otherwise.

Remarks

Use it for displaying message boxes in the Editor. If
message
is null or whitespace, an
ArgumentNullException
is thrown. If
messageText
is longer than 512 characters, it is truncated and the full message is logged to the console in markdown format.
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. If any button's text is longer than 64 characters, an
ArgumentException
is thrown.
For dialog boxes that might be shown repeatedly, consider using an overload of this method that takes a DialogOptOutDecisionType as described in the below the code example.
DisplayDialog1 (DisplayDialog)
Dialog box that has one button.
DisplayDialog2 (DisplayDialog)
Dialog box that has two buttons.
Note:
EditorUtility.DisplayDialog
and
EditorUtility.DisplayDialogComplex
are kept for backwards compatibilty. For new code, it is strongly recommended to use one of the new EditorDialog methods.
Additional Resources:

DisplayDialog(string, string, string)

This method displays a modal dialog.
public static bool DisplayDialog(string title, string message, string ok)

Parameters

title

The title of the dialog box. If left null, defaults to "Unity".

message

The text of the message.

Label displayed on the OK dialog button.

Returns

Type

Description

boolReturns
true
if the user clicks the OK button. Returns
false
otherwise.

Remarks

Use it for displaying message boxes in the Editor. If
message
is null or whitespace, an
ArgumentNullException
is thrown. If
messageText
is longer than 512 characters, it is truncated and the full message is logged to the console in markdown format.
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. If any button's text is longer than 64 characters, an
ArgumentException
is thrown.
For dialog boxes that might be shown repeatedly, consider using an overload of this method that takes a DialogOptOutDecisionType as described in the below the code example.
DisplayDialog1 (DisplayDialog)
Dialog box that has one button.
DisplayDialog2 (DisplayDialog)
Dialog box that has two buttons.
Note:
EditorUtility.DisplayDialog
and
EditorUtility.DisplayDialogComplex
are kept for backwards compatibilty. For new code, it is strongly recommended to use one of the new EditorDialog methods.
Additional Resources:

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.
public static bool DisplayDialog(string title, string message, string ok, DialogOptOutDecisionType dialogOptOutDecisionType, string dialogOptOutDecisionStorageKey)

Parameters

title

The title of the dialog box. If left null, defaults to "Unity".

message

The text of the message.

Label displayed on the OK dialog button.

dialogOptOutDecisionType

Where the result is stored if the user opts out of the dialog by checking the box.

dialogOptOutDecisionStorageKey

The key to use for storing the opt-out decision.

Returns

Type

Description

booltrue 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 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. If any button's text is longer than 64 characters, an
ArgumentException
is thrown.
If
dialogOptOutDecisionStorageKey
is not a valid XML tag, or more than 127 characters long, an ArgumentException is thrown. Care should be taken to ensure that the key is unique to the dialog box being displayed to prevent conflicts. The decision is only stored if the user checks the opt-out checkbox and clicks the Yes button. The user can reset the option in user preferences.
DisplayDialogO1 (DisplayDialog)
Dialog box that can opt out for this session.
DisplayDialogO2 (DisplayDialog)
Dialog box that can be opted out more permanently.
Note:
EditorUtility.DisplayDialog
and
EditorUtility.DisplayDialogComplex
are kept for backwards compatibilty. For new code, it is strongly recommended to use one of the new EditorDialog methods.
Additional Resources:

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.
public static bool DisplayDialog(string title, string message, string ok, string cancel, DialogOptOutDecisionType dialogOptOutDecisionType, string dialogOptOutDecisionStorageKey)

Parameters

title

The title of the dialog box. If left null, defaults to "Unity".

message

The text of the message.

Label displayed on the OK dialog button.

cancel

Label displayed on the Cancel dialog button.

dialogOptOutDecisionType

Where the result is stored if the user opts out of the dialog by checking the box.

dialogOptOutDecisionStorageKey

The key to use for storing the opt-out decision.

Returns

Type

Description

booltrue 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 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. If any button's text is longer than 64 characters, an
ArgumentException
is thrown.
If
dialogOptOutDecisionStorageKey
is not a valid XML tag, or more than 127 characters long, an ArgumentException is thrown. Care should be taken to ensure that the key is unique to the dialog box being displayed to prevent conflicts. The decision is only stored if the user checks the opt-out checkbox and clicks the Yes button. The user can reset the option in user preferences.
DisplayDialogO1 (DisplayDialog)
Dialog box that can opt out for this session.
DisplayDialogO2 (DisplayDialog)
Dialog box that can be opted out more permanently.
Note:
EditorUtility.DisplayDialog
and
EditorUtility.DisplayDialogComplex
are kept for backwards compatibilty. For new code, it is strongly recommended to use one of the new EditorDialog methods.
Additional Resources: