Display message in editor message box?

79397-drawing.png

How can I print a message in this message box?

This can be done in this way:

  1. Create an FNotificationInfo,
  2. Add the notification to the notification manager like this: auto NotificationItem = SlateNotificationManager::Get().AddNotification( Info );,
  3. Set its completion state: NotificationItem->SetCompletionState(SNotificationItem::CS_Success);
  4. Expire and fade out: NotificationItem->ExpireAndFadeout();

Here is an example:

	FNotificationInfo Info( LOCTEXT("HotReloadFinished", "Hot Reload Complete!") );
	Info.Image = FEditorStyle::GetBrush(TEXT("LevelEditor.RecompileGameCode"));
	Info.FadeInDuration = 0.1f;
	Info.FadeOutDuration = 0.5f;
	Info.ExpireDuration = 1.5f;
	Info.bUseThrobber = false;
	Info.bUseSuccessFailIcons = true;
	Info.bUseLargeFont = true;
	Info.bFireAndForget = false;
	Info.bAllowThrottleWhenFrameRateIsLow = false;
	auto NotificationItem = FSlateNotificationManager::Get().AddNotification( Info );
	NotificationItem->SetCompletionState(SNotificationItem::CS_Success);
	NotificationItem->ExpireAndFadeout();

	GEditor->PlayEditorSound(CompileSuccessSound);
2 Likes

Be sure to include:
#include “Widgets/Notifications/SNotificationList.h”
#include “Framework/Notifications/NotificationManager.h”
And in your Module.build.cs, add in PrivateDependencyModuleNames.AddRange(…) the module “EditorStyle”

1 Like

I also needed to add modules “SlateCore”, “Slate”, “UnrealEd”.
And to exclude compile error in cooking:

if (Target.Type == TargetType.Editor)
{
	PrivateDependencyModuleNames.AddRange(new string[] { "SlateCore", "Slate", "UnrealEd", "EditorStyle" });
}
1 Like