Announcement
Collapse
No announcement yet.
What's the best way to have a singleton-type object instance in every gamemode?
Collapse
X
-
joeGraf repliedGameState doesn't tick, but the GameMode does. Once per frame, update the GameState, which is then replicated to the clients.
-
HateDread repliedI 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
Code:PrimaryActorTick.bAllowTickOnDedicatedServer = true; PrimaryActorTick.bCanEverTick = true;
Thanks.
Leave a comment:
-
HateDread repliedOriginally posted by joeGraf View PostYou specify the class in your DefaultEngine.ini
Code:[/Script/Engine.Engine] GameEngine=/Script/YourGamePackage.YourGameEngine
Code:[/Script/Engine.Engine] GameEngine=/Script/MyGameName.CustomEngineClassName
Thanks, regardless.
Leave a comment:
-
Rama repliedOriginally posted by Marc Audy View PostOne 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.
Thanks Marc Audy and rest of Epic!
Rama
Leave a comment:
-
Marc Audy repliedOne 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.
Leave a comment:
-
joeGraf repliedYou specify the class in your DefaultEngine.ini
Code:[/Script/Engine.Engine] GameEngine=/Script/YourGamePackage.YourGameEngine
Leave a comment:
-
HateDread repliedOriginally posted by joeGraf View PostBest 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.
Originally posted by zazabar View PostIs this going to be on a client server or is this for a dedicated server?
Leave a comment:
-
joeGraf repliedBest 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.
Leave a comment:
-
zazabar repliedIs this going to be on a client server or is this for a dedicated server?
Leave a comment:
-
siq repliedIf you'll implement is as a singleton design pattern, then it will always be available every time from everywhere.
Leave a comment:
-
What's the best way to have a singleton-type object instance in every gamemode?
Hey guys,
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.
Thanks.Tags: None
Leave a comment: