dkr
(dkr)
January 31, 2015, 8:41am
1
Here’s how I have things set up:
I have my custom GameState class called UC_GameState. I made a blueprint out of it and assigned it as default GameState class.
Then I try to access it from my custom PlayerController class like this:
GameState = (AUC_GameState*)GetWorld()->GetGameState<AUC_GameState>();
check(GameState);
But the GameState is set to null, and editor crashes.
Shouldn’t GameState be available under client code?
Conceptually, think of the GameState as the state of the game. It can keep track of properties like score, list of connected players, number of caps in a CTF game, where the pieces are in a chess game, what missions you have completed in an open world game, etc. In general, the GameState should track properties that change during gameplay. The GameState exists on the server and all clients and can replicate freely to keep all machines up to date.
Thanks!
Jambax
(Jambax)
January 31, 2015, 11:51am
2
GameState should be available to all clients yeh, they have a local copy and it’s just a big list of replicated variables usually.
ShooterGame get’s the gameState in PlayerController like so:
AShooterGameState* const MyGameState = GetWorld() != NULL ? GetWorld()->GetGameState<AShooterGameState>() : NULL;
1 Like
dkr
(dkr)
February 1, 2015, 2:10pm
3
So does this mean that it’s possible for the GameState is null? Therefore I can’t rely on retrieving values from this object?
In my example I’m storing some properties of my “characters”. Like HealhtPoints, start rotation etc. Looks like this class isn’t suitable for this? Should I move this properties to GameMode class?
edit: Oh I see, It’s working now. (Because I’m not trying to access it from constructor of PlayerController).