So imagine a ‘ServerHelper’ object or some-such, whose methods could be called by players when joining, leaving, etc, to update values (i.e. a server-maintained clock). How could I make sure that one of these objects always exists, and is always accessible, in any match / game world? I always want to be able to query the server’s ‘time’ value from anywhere.
Best method is to subclass GameEngine and place a reference to your singleton object there. Then, it is accessible from every game mode and won’t be garbage collected. Be careful of objects that the singleton can refer to, because you can cause levels to stay in memory if you store references to them. Also make sure that any objects you store in that singleton use the smart pointers so you can check for them being still valid.
If I subclass GameEngine, how do I ensure that my version of it is the one that’s initialised/used?
Dedicated server, but with the ability for clients to get some of its information via RPCs (imagine clients that need to get the ‘server time’, so everyone can sync up, for example).
One other thing to consider is that in 4.4 the GameInstance feature will become available. This is a UObject with a lifetime of the Game Seassion, so in a stand alone game, there will be 1 and it will be there for the entire duration. If you use the multiplayer play in editor feature, then there could be multiples, one for each instance of the game.
I have refined my query now that I’ve tried implementing something in detail.
What I am after is a tick-able object that exists on the server and is replicated to the clients, and which can freely send RPCs between the server and the client.
This is for my time sync code, which currently exists in a custom player controller - it manages synchronizing the server time with all clients. Unfortunately, I need this time even when updating proxy actors, which don’t have a controller accessible on that particular machine. Additionally, I have tried GameState, but it does not Tick, even with