Skip to content

The Event Subsystem is an event-based communication within the game. It enables a more modular and maintainable architecture.

License

Notifications You must be signed in to change notification settings

MrRobinOfficial/Unreal-EventBus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

The Event Subsystem is an event-based communication within the game. It enables a more modular and maintainable architecture.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published