# Access to game state without cast every time?

**URL:** <https://forums.unrealengine.com/t/access-to-game-state-without-cast-every-time/379066>\
**Category:** Blueprint\
**Tags:** casting, game-state, unreal-engine, Blueprint, question\
**Created:** [December 12, 2016, 12:37pm UTC](https://forums.unrealengine.com/t/access-to-game-state-without-cast-every-time/379066 "2016-12-12T12:37:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Daniel\_K](https://forums.unrealengine.com/u/Daniel_K)\
**Post date:** [December 12, 2016, 12:37pm UTC](https://forums.unrealengine.com/t/access-to-game-state-without-cast-every-time/379066/1 "2016-12-12T12:37:10Z")

</div>

I understand concept of GameState, but I feel bit annoyed that I would need to cast it to my class every time I need to read or write variable from it. I have created a macro library blueprint essentially just to wrap around logic for variables stored in the game state. But I am wondering **if I can actually store MyGameState instance into some global-ish variable and have access to it from that macro library.**

Main thing that is bothering me about this is the need for execution pins whenever I need to cast. Especially for just getting values out of the game state it is rather annoying and not always feasible.

---

<div class="post-metadata">

**Author:** ![Azarus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Azarus](https://forums.unrealengine.com/u/Azarus)\
**Post date:** [December 12, 2016, 1:27pm UTC](https://forums.unrealengine.com/t/access-to-game-state-without-cast-every-time/379066/2 "2016-12-12T13:27:52Z")

</div>

Hey,

You can convert a cast function pure cast from impure cast. This allows you to leave an execution pin, but also might not be completely safe since you’re skipping the error check an impurecast provides.

See below the image:

[https://i.imgur.com/rsrMWU2.png](https://i.imgur.com/rsrMWU2.png)

Hope this help 🙂

---

<div class="post-metadata">

**Author:** ![Daniel\_K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Daniel\_K](https://forums.unrealengine.com/u/Daniel_K)\
**Post date:** [December 12, 2016, 2:37pm UTC](https://forums.unrealengine.com/t/access-to-game-state-without-cast-every-time/379066/3 "2016-12-12T14:37:35Z")

</div>

Ok thanks, that’s surely one way, but still feels kinda odd. Would be much easier in my opinion to have some place where I can store casted game state object into variable upon start (since this isn’t going to change in runtime) and then access it directly from other blueprints.

---

<div class="post-metadata">

**Author:** ![Azarus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Azarus](https://forums.unrealengine.com/u/Azarus)\
**Post date:** [December 12, 2016, 5:30pm UTC](https://forums.unrealengine.com/t/access-to-game-state-without-cast-every-time/379066/4 "2016-12-12T17:30:58Z")

</div>

You can maybe create a singleton object? Or store these variables in the game instance or game mode?

---

<div class="post-metadata">

**Author:** ![Daniel\_K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Daniel\_K](https://forums.unrealengine.com/u/Daniel_K)\
**Post date:** [December 12, 2016, 5:38pm UTC](https://forums.unrealengine.com/t/access-to-game-state-without-cast-every-time/379066/5 "2016-12-12T17:38:09Z")

</div>

Yeah I am kinda expecting it’s heading to C++ land for this. Not sure how game instance or game mode would be useful as I would need to cast those too only to get casted game state 🙂 That seems already easier to cast game state right away 🙂
