Is there a built in many to many, decentralized event system in C++?

Let’s say I want to listen to player death, weapon fired, character damaged, AI spawned, or any other number of events that can be sent by and from multiple places and I want to do so in a relatively generic way. For instance, the health component would fire an event on damage and any number of other systems (scoring, telemetry, stats, UI, etc.) would listen to it.

With the delegate system, either every listener would have to manually register with every health component or there would need to be a centralized in a singleton and listeners would register there and senders would tell the singleton when to send.

Essentially, I’m looking for a messaging system and I don’t think that UE5 has one. What are my options?

After a bit more digging and some discussion with co-workers, a potential solution would be to use static delegates. This wouldn’t be generic or decentralized, but it would allow me to build a many to many system without the runtime objects needing to know about each other.

I think its sounds like Game Ability System (aka GAS) is what youre after, there is an example of usage in the Lyra project. Because of the loose coupling it can be tricky to get your head around at first, it uses Gameplay Tags to trigger events :sunglasses:

Sounds like a Subsystem is what you’re looking for, probably a world subsystem.
You can access it from anywhere and they’re automatically created.
You’ll need to add some delegates to it, and call and bind them the usual way

1 Like

Yeah, that’s the brute force way (it’s what I mentioned in my second paragraph) but it’s not decentralized or generic. That subsystem would become a dumping ground for every hard-coded delegate that’s needed.

Well, this messaging system would have to exist somewhere and you would have to bind to listen to messages, it’s not like you want every actor in your game to receive them, you can use the subsystem as the intermediary between the sender and receiver.
Sounds like delegates is what you’re looking for, don’t know of any easier way of doing it and doesn’t sound like anything that exists in engine

there is a global events plugin on the marketplace written in c++ you could take look at for example. I think its like 10 bucks or less and I have several plugins from that author and they are all well made and well supported. I have no idea how it actually works but you define events using data assets.

other than that, what I actually do is just use game mode or similar as the centralized event relay. I don’t see any issue because it doesnt seem to break any SOLID principles, or at least doesn’t cause me any issues.

1 Like

If you’re willing to drop the “decentralized” from your requirements UE has a built-in MessageBus in the Messaging engine module. This would obviously require that you have one or potentially more instances that you can register to from all other systems. No need for any third party plugins or custom solutions.

1 Like