Tracking Multiplayer game time

I am developing a multiplayer RPG with a day night cycle of about 2 hours. The development of the clock is easy but I am having a diffcult time deciding on what object it should be long to. My initial thought was the GameMode object but I learned that it is not replicated to clients, the GameState is. Then I thought maybe the GameState or the GameInstance. I think the Game Instance maybe ideal because it is persistant across multiple levels. My thought is I create the clock, and then replicate it once to the clients upon joining, then the client’s clock can track time. I am thinking I don’t want to constantly replicate the clock to save some bandwith but at the same time the clock is extremely simple but it WILL change once every 5 seconds.

However I’m not entirely sure the best course of action on this. GameModule, GameState, GameInstance, or something else? And should I even be worried about a few extra bytes of data being sent over the network to clients?

A pragmatic solution would be to send the server time when the client connects for the first time and calculate the offset with the local client time. This way you will not have to keep the client updated when the clock ticks and you will not have to spend network bandwidth.

It might also be a good idea to trigger some events from the server at certain intervals, e.g. when nightfall begins. Then replicate this event to all clients (e.g. in a level blueprint, since day and night belong to the current world) and start the night-time transition.

Clients that are connected longer than one day might have an unsynced clock; you can use the predetermined nightfall event to recalculate the difference of server time and client time, again by sending the server time with the event as a parameter.

Hope this helps,

HyperReuts

My original idea did involve sending the server’s clock time to the clients and then just having them handle it from there. I’m still not entirely sure what object should be responsible for the tracking the clock though…

I must say I do like the idea of sending events for designated periods of the day i.e. (Sun Rise, Noon, Sun Set, Midnight, etc) That way if a client does get off a bit these replicated events can force an update to the clock! I’m definatly going to use that one! Thanks.

Or really what object should “own” the clock… My knowledge of UE4’s networking magic is at best theoretical with no real experience in using it. If the Game Mode owns it I will need to send it to some object on the client side. If the GameState owns it then I don’t want it replicating constantly with the game state or making the game state replicate constantly, and same with the GameInstance.

I know I can setup conditions for replication but I need some object that exists on the server and the client and is an actor… Oh! or maybe the clock itself is an actor (AInfo derrived)! Accessible through the GameInstance/GameState replicated only on joining the server and broadcasts the day time events… Question still remains which object is it better to be attached to? Instance or State… or is there something else?