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

NightmareGames
Mon, 24 Jul 2023 08:03:50 +0000
Programming & Scripting

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?

6 posts - 3 participants