FGlobalMessenger
#include <GlobalMessenger/Public/GlobalMessenger.h>class FGlobalMessengerDefined in GlobalMessenger.h:54
Inherits:
TSharedFromThis< FGlobalMessenger >
Inheritance diagram
Section titled “Inheritance diagram”---
config:
class:
hideEmptyMembersBox: true
---
classDiagram
class FGlobalMessenger["FGlobalMessenger"]
class TSharedFromThis__FGlobalMessenger["TSharedFromThis< FGlobalMessenger >"]
TSharedFromThis__FGlobalMessenger <|-- FGlobalMessenger
Collaboration diagram
Section titled “Collaboration diagram”---
config:
class:
hideEmptyMembersBox: true
---
classDiagram
class FGlobalMessenger["FGlobalMessenger"]
class FGlobalMessageListener["FGlobalMessageListener"]
FGlobalMessenger *-- FGlobalMessageListener
Class detail
Section titled “Class detail”---
config:
class:
hideEmptyMembersBox: true
---
classDiagram
class FGlobalMessenger {
+BroadcastMessage(const FGameplayTag &FilterTag, UObject *Pay
+AddListener(const UObject *NewListener, const FGameplay
+RemoveListener(const UObject *TestObject) bool
+ClearMappedDelegates()
+MappedDelegates : TMap< FGlobalMessageListener(), FGlobalM
}
Represents a global messenger for sending messages to multiple listeners.
The FGlobalMessenger class allows broadcasting messages to multiple listeners and managing those listeners. Messages can be filtered using gameplay tags to control which listeners receive the message.
Public Methods
Section titled “Public Methods”| Return | Name | Description |
|---|---|---|
void | BroadcastMessage | Broadcasts a global message to all registered listeners. |
void | AddListener | Adds a listener to the global message system. |
bool | RemoveListener | Removes a listener from the global message system. |
void | ClearMappedDelegates | Clears all mapped delegates in the global messenger. |
BroadcastMessage
Section titled “BroadcastMessage”void BroadcastMessage(const FGameplayTag & FilterTag, UObject * Payload)Defined in GlobalMessenger.h:75 Broadcasts a global message to all registered listeners.
This method iterates over all registered listeners and executes their corresponding callbacks. The callbacks are only executed if they are bound. If an unbound callback is encountered, a warning message is logged indicating that the owning object could be destroyed. It is recommended to call ‘RemoveListener’ on the object before destroying it to prevent this warning.
Parameters
Section titled “Parameters”-
FilterTagThe tag used to filter the listeners. Only listeners with matching tags will receive the message. If the tag is not valid, all listeners will receive the message. -
PayloadThe payload object to pass to the listeners. *
References
Section titled “References”MappedDelegatesVerboseWarning
AddListener
Section titled “AddListener”void AddListener(const UObject * NewListener, const FGameplayTag & FilterTag, const FGlobalMessageReceiveDelegate & Callback)Defined in GlobalMessenger.h:96 Adds a listener to the global message system.
This method adds a listener to the global message system by mapping it with the provided filter tag and callback. The listener will receive messages that match the filter tag when the messages are broadcasted using the BroadcastMessage method.
Parameters
Section titled “Parameters”-
NewListenerThe pointer to the object that will receive the global message. -
FilterTagThe tag that represents the message. Only listeners with matching tags will receive the message. -
CallbackThe delegate function to be executed when the message is received.
See also: BroadcastMessage
See also: RemoveListener
References
Section titled “References”RemoveListener
Section titled “RemoveListener”bool RemoveListener(const UObject * TestObject)Defined in GlobalMessenger.h:110 Removes a listener from the global message system.
This method removes the listener from the global message system by finding and removing the associated delegate from the mapped delegates container. The listener will no longer receive messages matching its filter tag. It is recommended to call this method before destroying the object to prevent warnings.
Parameters
Section titled “Parameters”TestObjectThe pointer to the object that needs to be removed as a listener.
Returns
Section titled “Returns”True if the listener was removed successfully, false otherwise.
References
Section titled “References”ClearMappedDelegates
Section titled “ClearMappedDelegates”void ClearMappedDelegates()Defined in GlobalMessenger.h:121 Clears all mapped delegates in the global messenger.
This method clears all mapped delegates in the global messenger. It empties the container of mapped delegates, effectively removing all listeners from the global message system. The cleared delegates will no longer receive any messages.
See also: FGlobalMessenger::~FGlobalMessenger
References
Section titled “References”MappedDelegatesVeryVerbose
Private Attributes
Section titled “Private Attributes”| Return | Name | Description |
|---|---|---|
TMap< FGlobalMessageListener, FGlobalMessageReceiveDelegate > | MappedDelegates |
MappedDelegates
Section titled “MappedDelegates”TMap< FGlobalMessageListener, FGlobalMessageReceiveDelegate > MappedDelegatesDefined in GlobalMessenger.h:56