Where is the best place to implement an Event Manager? In a Game State subclass?

Hi!

I’m watching a video about dependencies. He is going to use the Mediator pattern to avoid:

Instead, he is going to use an Event Manager:

And he is going to implement it on a Game State subclass.

Is it the best place to implement the event manager?

Thanks!

By the way, this is the video: https://www.youtube.com/watch?v=y4fE2JdFdvY

Implement it on Game State You can ,

I am used to imp on Subsystem

1 Like

Hi

Are you using C++ or BP?

If BP, you can use GameMode to handle that.

If C++ I encourage you use Subsystem, for Instance, UGameInstanceSubsystem class, subsystem will make your life easily.

1 Like

I also use subsystems for these. If enemies persist for only a single level, you can also use a world subsystem.

1 Like

It depends a lot on your own constraints.

If you’re building it just for you into one game, the GameState could be just fine.

If you’re building it into a plugin for use in multiple projects then the GameState becomes a less practical location because it requires a lot more setup to tie that specific game state type to the project specific classes.

Other people have suggested subsystems, and that’s definitely a good option (and it’s how I’ve implemented mine). There are multiple types of subsystems so you can pick the one that matches the lifetime you want for your Manager (like GameInstance vs World lifetimes).

A component is also possible solution (and would allow it to easily exist on a GameState). But then you have to contend with multiple instances possibly existing in your game (which may or may not be a deal breaker).

1 Like

GameplayMessageSubsystem is worth a look at… does what youre describing already using gameplay tag events. In the Lyra > Plugins > GameMessageRouter plugin is the implementation.

Also AsyncMessageSystem is out there… I haven’t used it but looks similar and can be used across threads.

1 Like

it also depends if you want it replicated in which case the GameState or a Component of it is best since Subsystems cant replicate

1 Like