# How to architect game wide variable access

**URL:** <https://forums.unrealengine.com/t/how-to-architect-game-wide-variable-access/422640>\
**Category:** Audio\
**Tags:** variables, unreal-engine, Blueprint, question, best-practice\
**Created:** [April 14, 2018, 5:08pm UTC](https://forums.unrealengine.com/t/how-to-architect-game-wide-variable-access/422640 "2018-04-14T17:08:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_ee5f06851](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ee5f06851](https://forums.unrealengine.com/u/anonymous_user_ee5f06851)\
**Post date:** [April 14, 2018, 5:08pm UTC](https://forums.unrealengine.com/t/how-to-architect-game-wide-variable-access/422640/1 "2018-04-14T17:08:08Z")

</div>

I am creating a game which has elements that react to sound.

I would like to have a central “engine” which does the sound-analysis, which I can then use in different actors to make them sound-reactive.

What is the best way to do this?

Right now I have an Actor BP doing the sound analysis and setting the output to a variable within that blueprint, which I then access from elsewhere, but it seems buggy, keeps leading to my project crashing.

---

<div class="post-metadata">

**Author:** ![AngeIV](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AngeIV](https://forums.unrealengine.com/u/AngeIV)\
**Post date:** [April 14, 2018, 5:26pm UTC](https://forums.unrealengine.com/t/how-to-architect-game-wide-variable-access/422640/2 "2018-04-14T17:26:10Z")

</div>

add to any pawn “pawn sensing component” and you will have access to hearing - so basically sound detection. you can detect sound form any source (so thrown physics objects etc) or just pawns via searching for “pawn make noise” function, or add a component called “pawn noise emitter”. from my experience I can say its best to work with that you already got in engine instead of reinventing the wheel 😉

---

<div class="post-metadata">

**Author:** ![MrMcKvarz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MrMcKvarz](https://forums.unrealengine.com/u/MrMcKvarz)\
**Post date:** [April 14, 2018, 6:20pm UTC](https://forums.unrealengine.com/t/how-to-architect-game-wide-variable-access/422640/3 "2018-04-14T18:20:41Z")

</div>

As to your title, GameInstance is used to store variables through the game. If you need interaction in one level, you can inherit from UObject, add your sound analysis functionality to it, spawn one in a world and pass sound data to it. Or you can do it directly in GameInstance.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ee5f06851](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ee5f06851](https://forums.unrealengine.com/u/anonymous_user_ee5f06851)\
**Post date:** [April 14, 2018, 6:28pm UTC](https://forums.unrealengine.com/t/how-to-architect-game-wide-variable-access/422640/4 "2018-04-14T18:28:49Z")

</div>

I’m detecting from the Windows Sound Card though via plugin…

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ee5f06851](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ee5f06851](https://forums.unrealengine.com/u/anonymous_user_ee5f06851)\
**Post date:** [April 14, 2018, 6:29pm UTC](https://forums.unrealengine.com/t/how-to-architect-game-wide-variable-access/422640/5 "2018-04-14T18:29:29Z")

</div>

OK and then within other Blueprints I would just add a reference to the GameInstance and access its variables?

---

<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:** [April 14, 2018, 7:15pm UTC](https://forums.unrealengine.com/t/how-to-architect-game-wide-variable-access/422640/6 "2018-04-14T19:15:20Z")

</div>

You do not even need a direct reference. Any blueprint can _GetGameInstance_ → _CastTo_ _YourGameInstance_.
