Whats the deferent between gamestate and game instance

whats the deferent between gamestate and gameinstance
what we should use for multiplayer UI (UMG)
cuz i see some use the gamestate and some use gameinstance

GameState is replicated extension of GameMode, since GameMode it self is not replicated and exists only on servers memory for security reasons. So GameState let clients access some game data which you would normally place in GameMode, primerly scores and match time, stuff that you usually see on scoreboard. This is only info that client will have and GameMode should have info which only server should know. You can ignore GameState if you creating single player only game.

GameInstance is a class that which state persists switching of levels, game mode switches etc. where classes like GameMode or PlayerController are being reset and any data stored in them is deleted and put to defaults again. Any data that you want to keep beyond levels and matches, for example ā€œwhat player did in specific moment so you can have consequence on other levelā€ should be placed here. This class is mainly helpful for single player gamesā€¦ but it can find uses in multi player too ;] I not sure if that class is replicated

For UI of multiplayer game you should use GameState and PlayerState ofcorse

3 Likes

nice explanation it help if u have any link to document or video to have more understanding itll be helpfull

in documentaion itā€™s called ā€œFrameworkā€ Gameplay Framework in Unreal engine | Unreal Engine 5.1 Documentation

1 Like

" I not sure if that class is replicated"

does it exists on server side and client side both?

I did a quick test and it looks like both client and server each have their own separate GameInstance.

This is actually logical, since the GameInstance is your personal user storage. So it keeps your data (e.g. game settings) even when you change from one multiplayer server to an other.

then how can you access a specific game instance of a player controller through a game mode

Its little old post, still Iā€™m adding more details incase in future if someone comes here.

Game state is like a object state that exists on server and replicated (all) clients.
game instance (GI), in analogy you can consider it as running exe process. Which exists on both client and server but they are independent and there is no logical relation between server GI and client GI.

For example when you start Fortnight game, that is nothing but Game instance, which is used to switch between widgets, querying master server and Join game session (match), switching between game modes (quad PvP, duo PvP or PvE). In all the cases you have only one game instance exists. It Gets destroyed when you close the game exe.

But GameState will be recreated for each game mode (session/match). When you play quad PvP you get one game mode, after that match finishes, if you join another PvP, you will get new GS.

Hope this helps. Sorry for typos.

1 Like

So if you have an open world with ā€˜automaticā€™ saving at trigger points (obtain new item, reach new level, etc), and multiple save slots the game has to choose between to load/save toā€¦ would you have a separate game instance thatā€™s loaded when the player picks a specific game slot to continue playing (that then determines which set of savegame variables to update in the savegame blueprint)? Or would you use gamestates/gamemodes to do this instead? The more I research game instances/modes/states the more confused I get over which one to use for the above!

1 Like