Where should I create a manager class : in GameMode or GameState?

Hello,

I’m developing a multiplayer (over network) basket ball game , and I’m wondering where’s the best place to keep references to a few manager classes I need to implement.

These managers will be in charge of managing the periods of the game

These managers have a double function : modify the gameplay ( running timers, updating the scores, the statistics of the players, etc…), and as such need to be run on the authoritative machine, and have accessors so that each client can display some informations on the HUDs ( like the remaining time for each period / possession ).

I guess that where I spawn these managers are of little importance, as they will all end in the world. But where I keep a reference to them is important.

What is the usual way of using such managers like this :

  1. Keep a reference (using UPROPERTY) on each of them in GameMode, so I’m sure they won’t be used by clients, and have all the infos needed by each client in replicated properties in GameState?
  2. Keep a reference (using UPROPERTY) on each of them in GameState, mark them as Replicated so the clients have access to the accessors functions, and put some conditions all over the functions which update the gameplay to make sure only the server calls them?
  3. Keep a reference (using UPROPERTY) on each of them in GameMode, and add a replicated property TWeakObjectPtr for each of them in the game state, so that everybody can access the functions they are concerned with, with the right level of authorization? (I’m not sure this is possible in fact)
  4. Split the managers in two : 1 class is in GameMode and is responsible of updating the gameplay. 1 class in GameState and is responsible of holding data to be displayed for each client. And the first class, when updating the gameplay, updates the values of the second class.

Any idea or recommandation?

Thanks

Let me bring some input of what I have right now, in the order I implemented it:

  1. I spawn my manager classes in the game state, and hold a reference to them
  2. I marked thoses properties as replicated
  3. I also had to mark as replicated the data I want in the managers
  4. It wasn’t working. I figured out I had to set the bReplicate and bAlwaysRelevant attributes to true in the managers.

Is there another way to make this work as intended, or do I have to go through all these steps? (Is it possible to replicate a non actor object?)

This is a bit confusing to me. UE alread has these ‘manager’ classes set up for you. All you have to do is use them.

You are tying to make manager classes to do the following:

Modify Gameplay - This should be done in the GameMode class

Update Scores - This should be done in the GameState class

Player Statistics - This should be done in the PlayerState class

Now all of these classes are replicated automatically. Check this out: Link to GameMode Docs… .you can see that you set these all up for the engine to manage internally… you just use them.

What you are trying to do is implement a system that already exists.

Look at the Gameplay Framework Docs to get a better understanding of this.

Good luck!

Thanks for your answer.

I didn’t want to put all the logic class straight into the game mode class, and to make it become a huge mess. That’s why I wanted to create managers to, well, manager specific parts of the gameplay.

You’re answer made me think a bit about all that, and I finally went the simple way:

my playerstate and gamestate are just data holder classes. All the fields are public and replicated (like in the Shooter example)
my managers now inherit from UObject instead of AActor, and are created in the GameMode, and update the attributes of the state classes accordingly.

It’w now much more clear and easy to use.

That implementation sounds good. Seems like it will keep things organized. =)