Skip to content

FGlobalMessenger

#include <GlobalMessenger/Public/GlobalMessenger.h>
class FGlobalMessenger

Defined in GlobalMessenger.h:54

Inherits: TSharedFromThis< FGlobalMessenger >

---
config:
  class:
    hideEmptyMembersBox: true
---
classDiagram
  class FGlobalMessenger["FGlobalMessenger"]
  class TSharedFromThis__FGlobalMessenger["TSharedFromThis< FGlobalMessenger >"]
  TSharedFromThis__FGlobalMessenger <|-- FGlobalMessenger
---
config:
  class:
    hideEmptyMembersBox: true
---
classDiagram
  class FGlobalMessenger["FGlobalMessenger"]
  class FGlobalMessageListener["FGlobalMessageListener"]
  FGlobalMessenger *-- FGlobalMessageListener
---
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.

ReturnNameDescription
voidBroadcastMessageBroadcasts a global message to all registered listeners.
voidAddListenerAdds a listener to the global message system.
boolRemoveListenerRemoves a listener from the global message system.
voidClearMappedDelegatesClears all mapped delegates in the global messenger.

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.

  • FilterTag The 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.

  • Payload The payload object to pass to the listeners. *


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.

  • NewListener The pointer to the object that will receive the global message.

  • FilterTag The tag that represents the message. Only listeners with matching tags will receive the message.

  • Callback The delegate function to be executed when the message is received.

See also: BroadcastMessage

See also: 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.

  • TestObject The pointer to the object that needs to be removed as a listener.

True if the listener was removed successfully, false otherwise.


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

ReturnNameDescription
TMap< FGlobalMessageListener, FGlobalMessageReceiveDelegate >MappedDelegates

TMap< FGlobalMessageListener, FGlobalMessageReceiveDelegate > MappedDelegates

Defined in GlobalMessenger.h:56