Message Dialog
FMessageDialog opens a native, modal pop-up window. It is handy in editor tools to inform the user or ask for confirmation.
Showing a dialog
#include "Misc/MessageDialog.h"
FMessageDialog::Open(EAppMsgType::Ok, FText::FromString(TEXT("Hello Unreal")));
Reading the result
Open returns an EAppReturnType::Type that tells you which button the user clicked:
const EAppReturnType::Type Result = FMessageDialog::Open(
EAppMsgType::YesNo,
NSLOCTEXT("MyTool", "DeleteConfirm", "Are you sure you want to delete these assets?"));
if (Result == EAppReturnType::Yes)
{
// Delete the assets
}
Message types
These are the button combinations you can pass as the first argument:
namespace EAppMsgType
{
/**
* Enumerates supported message dialog button types.
*/
enum Type
{
Ok,
YesNo,
OkCancel,
YesNoCancel,
CancelRetryContinue,
YesNoYesAllNoAll,
YesNoYesAllNoAllCancel,
YesNoYesAll,
};
}
The dialog is modal: it blocks the calling thread until the user closes it. Only call it from the game thread, and never in code that can run on a server or in an unattended build (commandlets, automation tests), because nobody will be there to click the button.
Use
FTextcreated withNSLOCTEXT/LOCTEXTinstead ofFText::FromStringfor text that users will see, so it can be localized.