Announcement

Collapse
No announcement yet.

What's the best way to have a singleton-type object instance in every gamemode?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    GameState doesn't tick, but the GameMode does. Once per frame, update the GameState, which is then replicated to the clients.

    Leave a comment:


  • replied
    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
    Code:
    PrimaryActorTick.bAllowTickOnDedicatedServer = true;
    	PrimaryActorTick.bCanEverTick = true;
    Any ideas? Still trying to grasp how some of the larger classes interact in a networked game.

    Thanks.

    Leave a comment:


  • replied
    Originally posted by joeGraf View Post
    You specify the class in your DefaultEngine.ini

    Code:
    [/Script/Engine.Engine]
    GameEngine=/Script/YourGamePackage.YourGameEngine
    Hi Joe, just wanted to double-check. Do you mean to suggest sub-classing UGameEngine, and writing, for example;

    Code:
    [/Script/Engine.Engine]
    GameEngine=/Script/MyGameName.CustomEngineClassName
    If that were the case, would I be including the preceding 'U' added to the name? That is of course only if this is the way you meant.

    Thanks, regardless.

    Leave a comment:


  • replied
    Originally posted by Marc Audy View Post
    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.
    New Game Instance class is awesome!

    Thanks Marc Audy and rest of Epic!



    Rama

    Leave a comment:


  • replied
    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.

    Leave a comment:


  • replied
    You specify the class in your DefaultEngine.ini

    Code:
    [/Script/Engine.Engine]
    GameEngine=/Script/YourGamePackage.YourGameEngine

    Leave a comment:


  • replied
    Originally posted by joeGraf View Post
    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?

    Originally posted by zazabar View Post
    Is this going to be on a client server or is this for a dedicated server?
    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).

    Leave a comment:


  • replied
    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.

    Leave a comment:


  • replied
    Is this going to be on a client server or is this for a dedicated server?

    Leave a comment:


  • replied
    How about using something like GameState?

    Leave a comment:


  • replied
    If 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.
Working...
X