[C++]Could someone tell me how to make a custom game state

This line of code doesn’t work (it compiles but “MainGameState” is NULL)

AMainGameState* const MainGameState = (() != NULL) ? ()->GetGameState<AMainGameState>() : NULL;

Also I set the GameStateClass to my custom game state class in my gamemodes c-tor:

ASLOPE01GameModeBase::ASLOPE01GameModeBase()
{
    GameStateClass = AMainGameState::StaticClass();
}

I don’t really understand how to use the gamemode and gamestate classes and to make my own custom children classes from them.

There possibility that gamestate is null pointer at that point, here do you call that first snippet?

How should it be done correctly?
Yes the first snippet is called in a constructor of an actor

you’ve set up your game state correctly, it’s just null at the moment of the actor’s construction becouse actors placed on level get constructed very early. Try to access it in the actor’s BeginPlay() instead.

Isn’t there a way to do it in the constructor because I do this in the base class constructor so when I inherit from it I can take some info out of the gamestate and put it in all the derived classes

you can do that same thing in BeginPlay() as well. When you override the BeginPlay method in dervied classes you call the Super::BeginPlay() method and if you cached all of that needed info in variables you can just access them then.