1. To create a new game state, create a new Blueprint that inherits from KGameStateBase.
2. There are several overrideable functions provided:
OnEnter() = This function is called once when the GameManagerSubsystem state machine gets set to this new state.
OnTick() = This function is called every time the GameManagerSubsystem ticks.
OnExit() = This function is called once when the GameManagerSubsystem state machine gets set to a different new state.
Use these functions to do setup, latent actions, and cleanup to control the flow of your game program. In example, you may have a loading state which OnEnter() loads the level and OnTick() waits for all levels to be loaded before automatically setting the next state to a gameplay state for the GameManagerSubsystem.The OnExit() tells all SaveAgents to then load using LoadSaveAgents() on the SaveManagerSubsystem and then calls Start() on the GameManagerSubsystem to signal all game manager listeners the game is ready.
The GameStateInterface can be implemented on any class to receive signals from the GameManagerSubsystem. When implementing this interface, you must call RegisterGameStateListener() from the KGameFrameworkStatics in BeginPlay(), otherwise the interface will not work. Two functions are provided for you to override to use:
Start() = When the GameManagerSubsystem wants to synchronously start all listeners in the game, this function will get called. You can override this function and put code to activate your actor here.
ReceiveGameStateChange = Override this function to receive KGameState changes from the GameManagerSubsystem. You can then code how you actor react to entering specific game states (ie. if the world should freeze when entering a cutscene).
To set states on the GameManagerSubsystem, simply call SetGameState(). The GameManagerSubsystem is a singleton that can be retrieved anywhere.
The KGameFrameworkStatics provide the GetGameState() function for any time you might need to check what the current KGameState is before proceeding in code.
The GameStateInterface will receive all game state changes which you can use to synchonize your classes to the state of the game.