Course contentsShow
← Unreal Engine Game Development
Lesson 199 of 8803. C++ and UObject ArchitectureFree lesson

Broadcasting Events with Multi-Cast Delegates

Master the implementation of multi-cast delegates to notify multiple independent listeners simultaneously when a specific game event occurs.

In this lesson, you will learn how to use Multi-Cast Delegates to broadcast a single game event to multiple independent listeners simultaneously.

The "Radio Station" Pattern

While Single-Cast delegates act like a private phone call between two objects, Multi-Cast delegates act like a radio station. When the delegate "broadcasts," every object currently "tuned in" (bound) to that delegate receives the signal immediately. This is essential for decoupled systems, such as a "Player Died" event that needs to notify the UI, the sound engine, and the score manager all at once, without the player needing to know that those other systems exist.

Implementing a Multi-Cast Delegate

To create a multi-cast delegate, we use the DECLARE_MULTICAST_DELEGATE macro. Note that unlike single-cast delegates, these cannot be exposed to Blueprints—they are strictly for internal C++ communication.

// 1. Declare the delegate type
DECLARE_MULTICAST_DELEGATE_OneParam(FOnPlayerDeath, float);

class AMyPlayer : public AActor
{
public:
    // 2. Create the delegate instance
    FOnPlayerDeath OnPlayerDeath;

    void Die()
    {
        // 3. Broadcast to all listeners
        OnPlayerDeath.Broadcast(100.0f); 
    }
};

Binding Listeners

Any class interested in the event simply needs a reference to your AMyPlayer instance to bind a function:

void UGameManager::Initialize(AMyPlayer* Player)
{
    // Bind a member function to the broadcast
    Player->OnPlayerDeath.AddUObject(this, &UGameManager::HandleDeath);
}

void UGameManager::HandleDeath(float ScorePenalty)
{
    // This runs automatically whenever the player calls Broadcast()
}

Why Use This?

The beauty of this approach is decoupling. Your AMyPlayer class doesn't need a list of pointers to UI widgets or sound managers. It just shouts into the void, and anyone listening receives the message. If you decide to add a new system (like an Achievement Manager) later, you don't have to touch the AMyPlayer code at all; you simply have the new class subscribe to the existing delegate.

Key Takeaway: Multi-Cast delegates provide a one-to-many communication channel that allows you to notify an unlimited number of observers about an event without the broadcaster needing to know who or what those observers are.