Where do I have to put the game logic?

Hi!

Where do I have to put the game logic? With game logic I mean when to know if the game is over, or to start the level again, etc.

Thanks

Gamemode. Read the documentaries which Epic Games provides. You have better vision.

GameMode, GameState, PlayerState and so on

GameInstance (an object spawned when you launch the application and that remains the same until you close it)
GameMode (spawned when a level is loaded)
GameState (spawned by the gameMode)
PlayerState (spawned when a PlayerController is spawned = when a player arrives in the game)

You have to pay close attention to what you do and where you do it when coding a multiplayer game.

When it comes to singleplayer, you can’t really “have it wrong” except for GameInstance stuff.

But here are the general guidelines I follow:

GameInstance - Holds any non-pointer persistent variables (persistent means that you need to store in between two levels and that you don’t need to store in a SaveGame)

GameMode - The overall game manager - starts and stops the current game space you’re in, handles the GameStates and how they rotate - an example might be “King of the Hill”

GameState - Keeps track of every data relative to the current state of the game (timers, scores, winning team) that all players in the game need to know about, handles scripted events related to the state For instance:

PregameState: Prevents player from performing any action, starts a timer and display it to everyone. When timer expires, ask KotH (KingOfTheHill game mode) to rotate to IngameState

IngameState: Enable player input, spawn a big loud noise and open players’ spawn gates. Open the Capture Point and store the amount of capture time both teams have. When one of the team reaches max score, asks KotH to switch to EndgameState.

EndgameState: Destroy every player’s characters and starts a cinematic showing the PlayOfTheGame then asks KotH to rotate to ScoreGameState etc.

PlayerController - HUD, Camera, Mouse, Keyboard, Gamepad, Inputs calling actions on the Character.

PlayerCharacter - Actions in response of Controller’s input + Holds personal infos and stats (Health, Ammo - but Ammo might on your Weapon Class if you can switch Weapons).

PlayerState - Holds every variable non related to the PlayerCharacter that needs to be known by everyone (best scores, current killing streak, player name…).

1 Like

GameInstance appears to be important for managing constant variables without pointers that need to be preserved between levels. It serves as the basis for the game and remains unchanged throughout the lifetime of the application. GameMode acts as a game manager, managing the overall game space, starting and stopping the game, and managing GameStates. It is like a conductor who orchestrates the flow of the game. For example, in the King of the Hill game mode, the GameMode will control the alternating PregameState, IngameState, and EndgameState. Try exploring more https://casinosanalyzer.com/online-casinos/superace88.com reviews for the rest of the game. GameState is responsible for tracking data related to the current state of the game, such as timers, scores, and winning teams. It also handles scenario events specific to the game state. It ensures that all players have access to the necessary information about the current game.

2 Likes