Tutorial: Using the GameplayMessageSystem

A short tutorial demonstrating how to utilize the GameplayMessageSystem in C++ and Blueprint

Updated 6 months ago Edit Page Revisions

Using the GameplayMessageSystem

This tutorial is intended to demonstrate the basics of how to Broadcast and Listen for messages using the GameplayMessageSystem.

Using the GameplayMessageSystem in C++

Include the GameplayMessageSystem

In any class where you Broadcast or Listen for messages, or otherwise interact with the GameplayMessageSystem, you will want to include the following header:

#include "GameFramework/GameplayMessageSubsystem.h"

Get the GameplayMessageSubsystem

UGameplayMessageSubsystem& MessageSubsystem = UGameplayMessageSubsystem::Get(this);

Broadcast a Message

UGameplayMessageSubsystem& MessageSubsystem = UGameplayMessageSubsystem::Get(this);

FGameplayTag ChannelTag; // You will need to assign this value as appropriate for your code
FGameMessage OutgoingMessage; // You will need to define the structure and fill out any members with data as appropriate for your code

MessageSystem.BroadcastMessage(ChannelTag, OutgoingMessage);

Register a Listener

UGameplayMessageSubsystem& MessageSubsystem = UGameplayMessageSubsystem::Get(this);

FGameplayTag ChannelTag; // You will need to assign this value as appropriate for your code
ListenerHandle = MessageSubsystem.RegisterListener(ChannelTag, this, &MyClass::CallbackFunction);

// Your class will also need a Callback Function defined as below

MyClass::CallbackFunction(FGameplayTag InChannel, FGameMessage InMessage)
{
    // Perform gameplay logic here
}

Using the GameplayMessageSystem in Blueprint

Broadcast a Message

image.png

Register a Listener

image.png

GameplayMessageSubsystem in Lyra

More to come!