Game State, Game Instance & Game Mode. Which one to use for what?

I’m making a simple co-op multiplayer game. You complete a level by defeating X amount of enemies and then you move on to next level (stream or not).

Where would be best to store the variable that determines if you won that level? So far, I’m using level blueprint to store “global” or level-specific variables but it seems like they’re best stored elsewhere. Game Mode seems to be server-only? So a client can’t access Game Mode vars? I don’t get it.

Hey, did you check out eXi’s Network Compendium? It’s huge, but important that you understand the whole framework and not only your 3 mentioned classes. I hope it helps you as much as it helped me! <3

4 Likes

Hey!
Super simple, just seems hard to understand :wink:

Let me explain:

GameMode: you have right, exist only on server. It is a secured actor which are hackproof because exist only on server, so clients cant modify it for example. But im sure many cause are there, why it is only on server :slight_smile:

No matter, exist only on server. Gamemode is the actor who owns and controll all of your rules which your game need.
For example imagine a shooter game with Team DeathMatch Mode!

Gamemode will check scores, time and will decide when match is over and which team is winner!
Clear and simple right? But…

GameState: gamestate is a simplified actor which will replicate to every client. So Server will have one GameState and every Client will have a copy of that!!!
Because of replication you can use unreal engines networking in gamestate, replicate variables, call multicast rpcs and so on.

Why Gamestate is important?

Go back our TDM example. You have two team which have team scores. when team 1 achieving score GameMode should decide and add one point to team 1.
So basically scoring as i said below controlled on server by Gamemode.
But you want show that score on Client Uis right? For that you need GameState because GameState can replicate variable, so team scores should be stored in gamestate but only Gamemode can change it :slight_smile:
Again clear right? For security reason we do not allow players to modify team scores, when someone dies we notify Gamemode this player died, Gamemode will decide we need add point for team or not, Gamemode modify point in Gamestate, Gamestate replicate score variable, Client Uis will refresh with new score :slight_smile:

Gamemode and gamestate arent persistent actors, that means when you change level new gamemode and new gamestate will be spawned.
So if you load a brand new level gamemode, gamestates will be destroyed (client gamestates too) and when new map loaded new gm gs will be spawned.

GameInstance:

Gameinstance actually is your game itself. Gameistance is persistent actor which will created when you first start the game and will be there as long your game runs.
No matter if you changing levels or players disconnecting from servers or go back to main menu, gameinstance will be there if game running.

Gameinstance is used for many cause like login and account check or giving informations about last played match or something.

Go back to our tdm example.

You want show some statistics for players after match ended, but you want to show that when new map is loading in background for example.
For this you can use gameinstance.

After match ended you send your statistics via gamestate and store in gameinstance, start load new level and you can use data from gameinstance, because gameinstance will be not destroyed :slight_smile:

This GameInstance example isnt the best, but i hope you understand the point.

33 Likes

Yo, that PDF is a gift from the heavens. Thanks.

1 Like

Thanks for the explanation, bookmarked.

i love u, thats exactly what i need

GameInstances are UObjects and not Actors.

1 Like

Thank you very much!

Thanks for the very easy to understand explanation!

So, for a single player game I only really need one of those, right?
I’m a beginner making a single player game and for now was only using the GameInstance to store player scores and all the rest. Is it ok for a single player game or will I be running into problems down the line that I am not aware of right now?

Hey,

Im also in need to understand these concepts. But that PDF link does not work anymore. Could you please share that if you have it with you ?

For solo game you may like this Romero Blueprints++: Table of Contents BP more

This link seems to have died; would it be possible for you to update it?

4 Likes

Technically for single player games, you could put most of your logic, event graph stuff, into your character. I e made lots of side solo projects and work on a multiplayer game, and the only time that game mode, game state, or game instance have been mentioned are for the multiplayer game.
Things to note though:
Controller is used to input
HUD is used to manage UI (add to viewport, updates, etc)
But these don’t need to be used in single player games, but can help in single player games to keep things organized.
The amount of nodes (logic) that I have placed inside of the character event graphs can cause unreal to get laggy when you open it to make changes, so at least try splitting that stress into the Controller and the HUD.