Game Instance, Game Mode, Player State, Player Controller... For what to use them?
Hello good people :) I need someone to explain some things if possible :D
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!!
asked Jul 24 '18 at 04:53 AM in Using UE4
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
answered Jul 24 '18 at 05:20 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here