Skip to content

Latest commit

 

History

History
99 lines (64 loc) · 3.01 KB

README.md

File metadata and controls

99 lines (64 loc) · 3.01 KB

Banner

license plugin-status maintenance-status

⚙️ Supported Versions

This plug-in was last built against Windows, Unreal Engine 5.4+.

However, this code should work on other Unreal Engine versions.

⚒️ Installation

You can install from the release section.

Alternatively, you can install this plugin via terminal with git.

Here is the command for installing it:

git clone git@github.com:MrRobinOfficial/Unreal-EventBus.git EventBus

📝 Quick guide

This plugin features a subsystem named UEventSubsystem, which enables you to register and invoke events. The event subsystem maintains a dictionary of events and their corresponding callbacks. These callbacks are stored in a list, allowing multiple callbacks to be registered for the same event. This design promotes a modular and maintainable approach to event-based systems.

The subsystem supports two types of invocation: UEventSubsystem::Invoke() and UEventSubsystem::InvokeWithPayload(). The payload is a UObject pointer that can be used to pass data between callbacks.

Inside that class, there a couple of functions that you can use.

Getting the event subsystem

#include "EventSubsystem.h"

UGameInstance* GameInstance = ...;
auto* EventSubsystem = GameInstance->GetSubsystem<UEventSubsystem>();

Registering events

UEventSubsystem* EventSubsystem = ...;

FOnEventSignature Delegate;
Delegate.BindUObject(this, &UEventSubsystem::OnPlayerDied);
EventSubsystem->RegisterEvent(TEXT("player_died"), Delegate);

// Callback will be invoked when `player_died` event is invoked
UFUNCTION()
void OnPlayerDied(UObject* Payload) { }

Unregistering events

With specific callback

UEventSubsystem* EventSubsystem = ...;

FOnEventSignature Delegate;
Delegate.BindUObject(this, &UEventSubsystem::OnPlayerDied);
EventSubsystem->UnregisterEvent(TEXT("player_died"), Delegate);

// Callback will be invoked when `player_died` event is invoked
UFUNCTION()
void OnPlayerDied(UObject* Payload) { }

Unregistering all events

UEventSubsystem* EventSubsystem = ...;
EventSubsystem->UnregisterAllEvents(TEXT("player_died"));

Invoking events

With payload

UObject* Payload = ...;
EventSubsystem->InvokeWithPayload(TEXT("player_died"), Payload);

Without payload

EventSubsystem->InvokeWithPayload(TEXT("player_died"));

🆘 Support

If you have any questions or issue, just write either to my YouTube channel, Email or Twitter DM.