Debugging a Blueprint Runtime Error: "Accessed None trying to read property" when trying to access GameState

I’m getting the error during runtime (presumably on every tick):
Blueprint Runtime Error: "Accessed None trying to read property As Mech Game State". Node: Return Node Graph: GetText_1 Function: Get Text 1 Blueprint: WPB_UI_Gameplay

This is coming from a binding in my hud’s UI widget:

It seems that most of the time, this error comes from someone trying to access something in the variable reference without actually setting the reference to an object, resulting in a null pointer.

However, I am setting it, right here in the widget’s event graph on Event Construct:

I’m noticing that a breakpoint on the “Cast to MechGameState” node is hit, but a breakpoint on the SET node is not. This tells me the cast is likely failing. On further inspection, the object that “Get Game State” is sending out is of type GameStateBase, and not my custom MechGameState.

It’s my understanding that classes which inherit from GameStateBase are created automatically as a singleton when the game starts. Yet, Unreal seems to be falling back to the base class rather than using the derived one.

Is there a step I’m missing, or am I going about this the wrong way?

Did you remember to tell the Game Mode to use the derived class:

image

And if you did remember, is the level using this Game Mode?

Did you remember to tell the Game Mode to use the derived class?
And if you did remember, is the level using this Game Mode?

It wasn’t my intention to touch GameMode at all, but it sounds like you’re saying GameMode and GameState have a close relationship. Must the GameState be set from inside the GameMode?

I’m not familiar with the UI in your screenshot. The closest thing I have is this, which I came upon while investigating:

It appears the game state is set to the base class, but all the options are greyed out for me, save for the GameMode itself.

I don’t recall specifically creating a GameMode, but I did find a MechGameMode C++ class, which I assume the editor made automatically at project creation time.

I haven’t touched the level’s specific game mode, as far as I know, although I don’t see an option for that in the outliner or the level blueprint. Where can I go to check that?

Must I set the default game state programmatically from inside the game mode’s C++, or could there be another reason why I’m not able to change those options?

The same goes for the entire framework. Eventually you may need your own pawn (already done, it seems) or a player controller. If you do not supply these, defaults are used instead. If you do not provide your own Game Mode, a default one is used.


You already have a custom Game Mode and even assigned it a non-default pawn, edit that blueprint to assign a game state class. You will need to ensure that you actually use the Game Made, too.

You could do it here:

You could do it there:

And also like so:

There is a project-wide setting and a world override for this level.

There were no places in the editor UI where I could change the GameState (they were all disabled). I suspect (though I’m not certain) this is because my game mode is a C++ class and not a blueprint.

I was able to set the game state from inside MechGameMode.cpp with the following code:
GameStateClass = AMechGameState::StaticClass();

Now my UI binding works with no errors.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.