Daily Unreal Column #9 - Slate Notification Manager
Issuing a warning or an error to the output log might not be the most efficient way of notifying a user about something going horribly wrong. Use Epic's way by utilizing Slate Notification Manager.
Before I start explaining how to use the notification manager, it is important to notice that it can only be used in C++. None of this functionality is exposed to blueprints.
Issuing a notification is very simple. First, make sure you have a Slate
module added to your .Build.cs
dependency module names.
PublicDependencyModuleNames.AddRange(new string[]
{
...
"Slate",
});
Then, its just a matter of querying the instance of the manager and, creating a notification info with the notification's content, and sending it. Below is the code that issues default notification with a text.
auto& NotificationManager = FSlateNotificationManager::Get();
FNotificationInfo NotificationInfo(FText::FromString("My notification"));
NotificationManager.AddNotification(NotificationInfo);
The above code will result in the following notification in the editor:
The FNotificationInfo
structure has a lot of properties that allows us to tailor the notification to our needs like fade in and fade out time, whether it should use throbber or not etc.
It also allows to use custom widget as long as it implements INotificationWidget
interface but I will not be showing how to do it here as it would bloat the today’s post.
Oh this is really cool!