How do I set a custom Game State Class?

The option is greyed out in the editor and I can’t seem to figure out how to set it via code just from looking at the documentation.

I tried adding GameStateClass = AMyGameState; and GameStateClass = AGameState::AMyGameState(); but they obviously didn’t work.

GameStateClass = MyGameStateClass::StaticClass();

If you want to be able to change it in the editor with the dropdowns you will need to create a custom game mode also.

If not use the solution offered by DarthB

Yes, I’ve created a custom game mode. Thanks!

error C2653: 'MyGameStateClass' : is not a class or namespace name

Also tried AMyGameStateClass, and AMyGameState. Am I missing an include or something?

Yep, I’d forgotten to include MyGameState.h


I had an issue with this as will. I’m not sure why but the problem started after I moved my custom GameMode code from blueprint to C++. I was able to fix it by creating a blueprint from the C++ custom GameMode and set the world GameMode object to that new blueprint with the C++ GameMode as the parent. I was then able to set the custom GameState blueprint from the drop down menu in world settings.