Game Instance, Game Mode, Player State, Player Controller... For what to use them?

GameMode controls the game, everything related to game rules that are global hence the name Game Mode since game mode program should be in there. GameMode indeed resets with the world so it should keep the rules in scope of single match or level. Game Mode is indeed not replicated

GameInstance is same as GameMode but without tie to world level, everything that should be keeped between the level should be there

PlayerController represents the player (or rether it’s controller) it should work same way as GameMode but related to invidual player, Player data inside player pawn dies with the pawn, so controller should keep persistent information beyond player respawn circles. This object is only exists on owner client and server.

GameState and PlayerState are replicable extensions of GameMode and PlayerController, generly it should not have a code just values set by GameMode and PlayercController that will be replicated to all clients

If you use UMG, HUD should be initiated in PlayerController, you can also make HUD class to control that more and have access legacy HUD canvas. With UMG code of UI should be in Widget Blueprint it self and Widget Blueprint should idependly collect all data from other classes to display insted of classes sending it to it. UI should not have any gameplay data either, or else you want to process it in some way for UI use (like value ease in outs etc.)

Stuff like Health should be on pawn since it is health of pawn.

Keep in mind that there not stone written rules where everything should be, place things wherever you think that it plays bigger role in

1 Like

Hello good people :slight_smile:
I need someone to explain some things if possible :smiley:

OK, I think I know basics…

Game Instance is the game itself and it exists until the game is closed. (Correct me if I’m wrong)

Game Mode exists only on the server and clients can not access it, only server can. It is destroyed every time a new level loads.(Correct me if I’m wrong)

Game State is created for every player that joins the server, but it is only a copy of a true thing that runs on server.
Server creates Game State, server modifies it and server replicates it to all clients. It is also destroyed after a new level loads. (Correct me if I’m wrong)

Player Controller is created for every client on the server. It is created by the client and it does not replicate. Also destroyed after a new level loads. (I’m so unsure about this, correct me pls)

What I really want to know is for what to use them?

What logic to run on Game Instance and what on Game Mode.
For example, where should I create Main Menu Widgets…
Where should I put Health, Coins and other.

Where should I create HP widget, Time Remaining widget, Crosshair widget…

PLEASE someone explain, I want to do things the right way…

Thank you very much!!

Thank you very much!!!
This helps a lot!

Can you tell me one more thing:
Because Player Controller is destroyer every time a new level loads, is it better practice to create Menu Widgets inside Game Instance or not? TNX :smiley:

You could if viewport not resets, but there really no point :stuck_out_tongue: just initiate UI on level start it cost nothing. Remeber that UI should not contain any game data, insted UI code should get data to display from other classes, so don’t duplicate variables it’s just waste of memory space