Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrrobinofficial/unreal-eventbus
The Event Subsystem is an event-based communication within the game. It enables a more modular and maintainable architecture.
https://github.com/mrrobinofficial/unreal-eventbus
cplusplus cpp event eventbus plugin unreal-engine unreal-engine-plugin
Last synced: 3 months ago
JSON representation
The Event Subsystem is an event-based communication within the game. It enables a more modular and maintainable architecture.
- Host: GitHub
- URL: https://github.com/mrrobinofficial/unreal-eventbus
- Owner: MrRobinOfficial
- License: mit
- Created: 2024-08-07T21:02:17.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-12T11:30:25.000Z (5 months ago)
- Last Synced: 2024-09-29T12:22:57.340Z (3 months ago)
- Topics: cplusplus, cpp, event, eventbus, plugin, unreal-engine, unreal-engine-plugin
- Language: C++
- Homepage:
- Size: 11.7 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
![Banner](Resources/Banner.png)
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/mrrobinofficial/unreal-eventbus/blob/HEAD/LICENSE.txt)
![plugin-status](https://img.shields.io/badge/plugin_status-ready_to_use-green)
![maintenance-status](https://img.shields.io/badge/maintenance-passively--maintained-yellowgreen.svg)## ⚙️ 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](https://github.com/MrRobinOfficial/Unreal-EventBus/releases/latest).
Alternatively, you can install this plugin via terminal with [*git*](https://git-scm.com/).
_Here is the command for installing it_:
```console
git clone [email protected]: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
```cpp
#include "EventSubsystem.h"UGameInstance* GameInstance = ...;
auto* EventSubsystem = GameInstance->GetSubsystem();
```### Registering events
```cpp
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
```cpp
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
```cpp
UEventSubsystem* EventSubsystem = ...;
EventSubsystem->UnregisterAllEvents(TEXT("player_died"));
```### Invoking events
#### With payload
```cpp
UObject* Payload = ...;
EventSubsystem->InvokeWithPayload(TEXT("player_died"), Payload);
```#### Without payload
```cpp
EventSubsystem->InvokeWithPayload(TEXT("player_died"));
```## 🆘 Support
If you have any questions or issue, just write either to my [YouTube channel](https://www.youtube.com/@mrrobinofficial), [Email](mailto:[email protected]) or [Twitter DM](https://twitter.com/MrRobinOfficial).