Proper Game and Player State Architecture and Workflow

Hello All!

I’ve been searching for a while, but documentation on how to properly use these are lacking to say the least.

Current Set Up:
I have a custom game mode and controller. The player operates a ‘selected’ Pawn, while the others are essentially Ai bots, that determine what to do based on the current state of play (pre-action/action/post-action/etc).

What I want to accomplish:
I want my game to be able to transition between multiple states of play, so that I can avoid lots of nested ifs in a blob class. I originally thought about writing my own state machine, and using it in combination with the player controller, but eventually this will need to be multiplayer, and so scalability (sp) and compartmentalization are a priority.

Am I better off writing my own state machine to handle gameplay? If not, what is the proper way of setting up and using the game state class in unreal?

The GameState class in Unreal is not tied to the concept of state machines. The GameState and PlayerStates are simply data containers that are, in conjunction with GameMode, setup to replicate to all multiplayer clients. Their purpose could be easily achieved with custom actors, but this setup is meant for our convenience, because with this setup you have a place for every type of replicated variable:

  • GameMode only exists server-side
  • GameState exists on all clients
  • PlayerController (per player) exists only on the server and that player’s client
  • PlayerState (per player) exists on all clients

As for working with a state machine approach in Unreal. You can either use maps for this- having one map for the main menu, separate maps for gameplay, etc. But if you want to have different states within one map, you will have to write your own state machine. You can store any data necessary for keeping the state machine synchronized on all clients in GameState though. Hope that clarifies things. :slight_smile: