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 :
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?
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?
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)
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.
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.
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.