Casting to Gamestate fails

I’m attempting to cast to gamestate from a class blueprint to update the gamestate variables. I can create the node and access the custom event I’m using to update the variable (ok, I just realized I can access the set variable directly…). But the cast is failing. Any idea why the cast would fail?

On the topic of gamestate, I’m a little fuzzy on exactly its purpose and use. The documentation page for it is fairly vague. I do need to manually update any game related variables in the game state? Should I be pulling info for the HUD from there?

Make sure that you have your Game state set as the active one for your level under world settings. The Game State object is created at the start of the level, so if it’s not set as the Gamestate you want to use, the cast will fail since it either is creating no Gamestate or trying to cast a Gamestate of a different class.

Gamestates are used to control game flow. Opening cutscene, Gamestate 1. Player 1 start, another Gamestate. Player 1 dies, another Gamestate. Player 2 start, yet another. You can also put variables you want to be able to access from anywhere in the level into the Gamestate blueprint, like game rules and governing variables and such.

Aha! That was the issue. I thought I had it set everywhere, but I guess not.

So, a game state instance is created for each player, at every point? But based on the gamestate blueprint? All uh, “replicated” so they’re all the same? How does it control game flow? By holding rules and such inside it?

Your Game Mode generally holds the meta rules and your GameState actually carries out the local rules based on the player’s state. So your Game Mode would dynamically change the GameState depending on what’s happening. So for instance, your GameState would start as “In Game” with rules that govern moving the player, where they can go, things they can do, that kind of stuff, and everything would be fine and good until your character gets shot in the head. In Game then says oh well a headshot makes the player lose all his health and your Game Mode is then like Whoa man there’s no more health here let’s change states to “Dying”. That kind of thing. Of course, Modes and States are very freeform, and this is just an example. You can make entire games without ever utilizing Game Mode or GameStates, they just make it easier to govern things in-game when some objects may be created or destroyed throughout, so putting game logic on these objects (the ones that great created and destroyed throughout the game) would be difficult to maintain.

Curiously, Epic has yet to release any videos outlining how to use Game Modes and their child pieces and the documentation ( is just about as vague as I was. :smiley: Just don’t worry about doing things the “right way” and just focus on getting your game to work. In GFX they say “If it looks right, it is right.” In Game Develpment, I say “If it works, it’s right. As long as it has no huge security flaws and a fluid framerate and doesn’t crash. Then yeah.”

Sorry for pushing, but i had the same problem, and changed world-settings, but it didn’t work, and i was just getting crazy, i couldn’t solve that problem. Until i did something stupid :stuck_out_tongue: and the engine crashed. After a restart, everything was working. So maybe you have to restart the engine, after changing the world GameState?!?!?!?
Just in case, someone has the same problem…

Thanks a lot ! Was in the same situation, changed in world-settings and nothing. Saw your post, rebooted the engine, all good now :slight_smile: