Where do I have to put actions when the game state changes

I’ve just started to learn Unreal Engine implementing a clone version of Atari’s Pong game.

I’m thinking about where to put the code to change the state of the game. I have an enum in the GameState class to manage when the game hasn’t started, or when we are playing the game. In case when someone scores I decided that I have to stop the ball and move it to its initial position.

My problem comes here because I don’t know where to put the code to do that: on GameMode class or on GameState class.

Where do I have to put that code?

If you’re always staying in the same map, either works – you’re talking about States so it just make sense to have it in your GameState class (although that’s not the only solution; depending on your implementation, that could also be managed by your player controller :)).

If you have states or in general variables that you want to persist across different maps, then you’ll want to use your custom GameInstance class.

Hope that helps!


Thanks for your answer but, as far as I know, GameState doesn’t have any StartPlay method.