Role of GameMode, PlayerController, GameInstance
Unreal Framework seen through ProjectTB’s menu and combat structure
The articles written on this blog were created with the goal of teaching. Also, the information in the article may be incorrect, so please be careful.
As your Unreal project grows, it's easy to start randomly adding functionality to GameMode, PlayerController, and GameInstance. ProjectTB reorganized the responsibilities of each class, separating the main menu and combat.
GameMode is the rules of the current world
TBMainMenuGameModeis responsible for the main menu flow,TBGameModeis in charge of expedition and combat rules. One GameMode doesn't take over all menus, character selection, and combat.
MainMenu World
TBMainMenuGameMode
TBMainMenuPlayerController
TBMainMenuWidget
Battle World
TBGameMode
TBPlayerController
TBExpeditionHUDWidget
GameMode is created when the world changes. Therefore, it is good to include the rules of the world, such as winning or losing the current battle, deployment restrictions, and enemy creation.
PlayerController is the player's input and intent
The PlayerController connects commands the player gives to the world, such as mouse clicks, selections, and camera input. In ProjectTB, left-click ally selection and enemy hover information were separated, and battle target designation was kept separate.
Rather than putting all logic into a widget when a UI button is pressed, it is safer to send a request to the verification function of Controller or GameMode.
GameInstance survives between worlds
GameInstance is maintained even if you move the map. It is good to have objects with a longer lifespan than the world, such as campaign information or global subsystems selected from the main menu.
However, if you put all the global variables into GameInstance, it becomes a huge manager class. Independent responsibilities such as UI and storage areUGameInstanceSubsystemcan be separated.
The criterion for choosing a class is not a convenient approach. You need to decide which world the data should live in, who should verify the rules, and who will own the input.