GameMode vs GameState

Hey all,

So I’m setting up a GameMode and GameState for my project. After reading online a lot about the differences between the two, I’ve downloaded the shooter game to get an idea as well.

So I want to see if I had the correct idea… in super laymen terms.

GameMode seems to be the referee, while GameState is kinda of like the assistant ref, just keeping an eye one the clock, who’s on what team, what the score is as a whole (PlayerState keeps track of individual scores), and possibly where those players might be on the field if we care about that sort of thing, but mostly TEAM stats - not individual state.

If I hit a player, I don’t tell GameState. I tell GameMode and it will decide whether I really hit the player or not. Also, no variables, whether public, private, or protected, should ever changed within GameMode, as those are the rules that are to be set and maintained through the match. If I want rules to change in the middle of a match, whether it’s a major or minor change, should I make a separate GameMode and just swap the GameMode?

Thanks in advance!

  • Austin

Simply GameMode is about rules and managing them, GameState is about game statistics, scores. GameState is a part of GameMode. But detailed answer would be helpfull for me too.

Yeah. I was just attempting to put it in terms more people may understand… although I’m still assuming the majority of readers will have a basic idea of sports and referees.

#They Are Very Different In Multiplayer Game

Game Mode = Only Exists on the server, and controls how players login to the match, and how player units are spawned. You can stop a player from joining a multiplayer game here, or know when a player has left. And again this actor only ever exists on the server.

Game State = Ideal for managing all aspects of a replicated world, such as world time, world object positions not owned by a player, AOE damage zones, neutral replicated gameplay elements of any kind.

This actor exists for client and server and allows for each client to know stuff about the world.

Again a great example is World time where you want the client to know what what the session / turn / current mission time is as propogated to each client from server calculations that are done in Game State class on the server, and replicated to each client using a replicated Time variable.

The bulk of actual game-time related stuff in multiplayer game has to be done in Game State if it is anything you want clients to know about locally :slight_smile:

Rama

If I’m working with a single player game, does it still make sense to use GameMode as the decision maker? Even though it’s not a “server”, it still acts like a server and still makes the decisions/actions a server would?

Thanks!

Yes, it is the common/official way. But there are some other ways of course so you don’t have to.

This answer should be put into the documentation, in big bold letters!

1 Like

What’s the difference between player state and game state?

In short, GameState is replicated across server and client. GameState maintains an array of PlayerStates as well.

GameState would have things like total kills per team, time remaining, which zones are being dominated by which teams, etc. PlayerStates hold things that are specific to the inidividual. i.e. - numKills, numDeaths, shotsFired, numHitsOnTarget, zonesCaptured, etc. Use some of these fields, the client can calculate other data the server doesn’t need to waist cycles on (K/D ratio, hit ratio, etc)

I’d like to get the GameState when I’m in the editor. I’ve tried doing this in my UActorComponent that is supposed to be attached to an AActor…

auto EditorWorld = GEditor->GetEditorWorldContext().World();
	if (EditorWorld) {
		auto GameState = EditorWorld->GetGameState();
		if (GameState) {
			BMoveSetupComponent = Cast<UBMoveSetupComponent>(GameState->GetComponentByClass(UBMoveSetupComponent::StaticClass()));
		}

	}

But my GameState is always null. I’m doing this while the editor is not running though. Is that the issue? I can’t get the GameInstance while the editor is not playing?