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

**URL:** <https://forums.unrealengine.com/t/debugging-a-blueprint-runtime-error-accessed-none-trying-to-read-property-when-trying-to-access-gamestate/1238338>\
**Category:** Programming & Scripting\
**Tags:** gamestate, unreal-engine, Blueprint, question\
**Created:** [July 24, 2023, 8:03am UTC](https://forums.unrealengine.com/t/debugging-a-blueprint-runtime-error-accessed-none-trying-to-read-property-when-trying-to-access-gamestate/1238338 "2023-07-24T08:03:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![NightmareGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nightmaregames/32/711529_2.png) [@NightmareGames](https://forums.unrealengine.com/u/NightmareGames)\
**Post date:** [July 24, 2023, 8:03am UTC](https://forums.unrealengine.com/t/debugging-a-blueprint-runtime-error-accessed-none-trying-to-read-property-when-trying-to-access-gamestate/1238338/1 "2023-07-24T08:03:50Z")

</div>

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:

 ![2023-07-24 00_43_33-Mech - Unreal Editor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/6/a/06a8266db18557d5521a63eaf010c6e208a30335.png)

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:

 ![2023-07-24 00_50_31-Mech - Unreal Editor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/5/3/e5312f6688240aac27f843bd49a987874cdb0f59.png)

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?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 24, 2023, 8:23am UTC](https://forums.unrealengine.com/t/debugging-a-blueprint-runtime-error-accessed-none-trying-to-read-property-when-trying-to-access-gamestate/1238338/2 "2023-07-24T08:23:14Z")

</div>

> [@NightmareGames](#):
>
> 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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/8/0/88090d9daab89c5ab370a7a9da046caee6086e3d.png)

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

---

<div class="post-metadata">

**Author:** ![NightmareGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nightmaregames/32/711529_2.png) [@NightmareGames](https://forums.unrealengine.com/u/NightmareGames)\
**Post date:** [July 25, 2023, 6:58am UTC](https://forums.unrealengine.com/t/debugging-a-blueprint-runtime-error-accessed-none-trying-to-read-property-when-trying-to-access-gamestate/1238338/3 "2023-07-25T06:58:38Z")

</div>

> 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:

 ![2023-07-20 00_37_38-](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/e/0/de006af8963b5f8fecd153ff23eee851ed80a191.png)

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?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 25, 2023, 7:16am UTC](https://forums.unrealengine.com/t/debugging-a-blueprint-runtime-error-accessed-none-trying-to-read-property-when-trying-to-access-gamestate/1238338/4 "2023-07-25T07:16:43Z")

</div>

> [@NightmareGames](#):
>
> it sounds like you’re saying GameMode and GameState have a close relationship

> **[Game Mode and Game State](https://docs.unrealengine.com/4.27/en-US/InteractiveExperiences/Framework/GameMode/)**
>
> Overview of the Game Mode and Game State

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:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/71379d01d993766a1b1307ddbf1a25a13721e0fa.png)

You could do it there:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/1/5/d159dba1be657cb516b99f74ee46af9aa75eb849.png)

And also like so:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/e/f/2efc9bcd981adbbdcf6211111a785e2ef5ceec49.jpeg)

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

---

<div class="post-metadata">

**Author:** ![NightmareGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nightmaregames/32/711529_2.png) [@NightmareGames](https://forums.unrealengine.com/u/NightmareGames)\
**Post date:** [July 29, 2023, 7:49am UTC](https://forums.unrealengine.com/t/debugging-a-blueprint-runtime-error-accessed-none-trying-to-read-property-when-trying-to-access-gamestate/1238338/5 "2023-07-29T07:49:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [August 28, 2023, 7:50am UTC](https://forums.unrealengine.com/t/debugging-a-blueprint-runtime-error-accessed-none-trying-to-read-property-when-trying-to-access-gamestate/1238338/6 "2023-08-28T07:50:16Z")

</div>

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