# Getter node necessary to avoid scope problem?

**URL:** <https://forums.unrealengine.com/t/getter-node-necessary-to-avoid-scope-problem/331978>\
**Category:** Editor Scripting\
**Tags:** variables, reference, scope, unreal-engine, bug-report, question, Blueprint\
**Created:** [September 12, 2015, 3:40pm UTC](https://forums.unrealengine.com/t/getter-node-necessary-to-avoid-scope-problem/331978 "2015-09-12T15:40:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shrooblord](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shrooblord/32/88712_2.png) [@Shrooblord](https://forums.unrealengine.com/u/Shrooblord)\
**Post date:** [September 12, 2015, 3:40pm UTC](https://forums.unrealengine.com/t/getter-node-necessary-to-avoid-scope-problem/331978/1 "2015-09-12T15:40:23Z")

</div>

Hi Epic Staff,

Seems I ran into a bit of a problem scripting my blueprints and I was wondering if it’s because of some sort of bug.

Here’s the situation.  
I have a blueprint called _room_ that will check the level for any other blueprints of the type _room_ since each needs to have its own ID.  
So it uses a GetAllActorsOfClass node with class set to _room_ and a ForEach loop to determine the other _rooms’_ ID value. After assigning itself an ID, it will go on with additional roombuilding functionality with local variables and such to create floortiles and whatnot.

However.

Although placing multiple instances of _room_ in the level seems to allow each to assign itself its own unique ID, it seems to clog up the rest of the blueprint (which is all in the Construction Script), making it seem as if the blueprint is somehow corrupt. Additionally, although one room in the level works fine, placing a second will make the first break, removing all functionality post-Room ID assignment.

I have figured out a solution to this problem and it is as can be seen in my screenshots.

Graph with function as solution - encapsulating the two room IDs in a function solves everything.

 ![58348-screen+shot+2015-09-12+at+17.23.48.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/e/6/ae61ffe06bddf32ddf936f78201459ebc193ff1f.png)

Function

 ![58349-screen+shot+2015-09-12+at+17.23.57.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/5/1/d51edb06250733f27cc0016af0bfb7d5dd63e673.png)

That’s it! That’s all there is to it. There’s not even one node changed from my previous setup. The only difference is that now, the **RoomID** variable native to the blueprint calling the script (the **local** instance of **RoomID** ) and the **RoomID** residing inside the blueprint referenced by the ForEach loop are both inside a function together, separated from the rest of the graph.

Now I didn’t just invent this myself. I was reading online about similar problems and found that this is also the solutiokn to what you have to do when a variable is “not in scope”, generally the case when two blueprints need to communicate with each other.

First, I set this up using a Cast node, and that yielded the same functionality, i.e. fixed the problem. But the editor warned me a Cast was not necessary as the Array item was already referencing the specific actor _room_. So I put the two variables inside a function instead, no Cast involved, and it also solved the problem!

I suspect there’s something weird going on with variable scope. Putting these variables inside a separate function has effectively turned the function into a Getter, actively calling the values of the variables (correct?). I do not know why it breaks the functionality of the rest of the blueprint without this Getter, but it is mighty strange.

Hope you can figure out what this all means.

Thanks,  
Shrooblord

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b9532c9a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b9532c9a](https://forums.unrealengine.com/u/anonymous_user_b9532c9a)\
**Post date:** [September 14, 2015, 5:55pm UTC](https://forums.unrealengine.com/t/getter-node-necessary-to-avoid-scope-problem/331978/2 "2015-09-14T17:55:29Z")

</div>

Hi Shrooblord,

I just want to make sure I fully understand what you are saying so that I can reproduce this effectively. Your getter function, which simply takes the room ID variable from the “get all actors of class” node and compares it to the room ID var of the blueprint in question, does not work in the main event graph. It only works if you have it separated out into its own function?

---

<div class="post-metadata">

**Author:** ![Shrooblord](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shrooblord/32/88712_2.png) [@Shrooblord](https://forums.unrealengine.com/u/Shrooblord)\
**Post date:** [September 18, 2015, 7:32am UTC](https://forums.unrealengine.com/t/getter-node-necessary-to-avoid-scope-problem/331978/3 "2015-09-18T07:32:53Z")

</div>

Yes, that is the case. If the getters are in the main event graph, the rest of the construction script does not execute.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b9532c9a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b9532c9a](https://forums.unrealengine.com/u/anonymous_user_b9532c9a)\
**Post date:** [September 18, 2015, 3:04pm UTC](https://forums.unrealengine.com/t/getter-node-necessary-to-avoid-scope-problem/331978/4 "2015-09-18T15:04:22Z")

</div>

Do any specific errors appear on screen or in the output log when you attempt this without the custom function?

---

<div class="post-metadata">

**Author:** ![Shrooblord](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shrooblord/32/88712_2.png) [@Shrooblord](https://forums.unrealengine.com/u/Shrooblord)\
**Post date:** [September 18, 2015, 9:01pm UTC](https://forums.unrealengine.com/t/getter-node-necessary-to-avoid-scope-problem/331978/5 "2015-09-18T21:01:34Z")

</div>

The only thing I’ve been able to debug in this is that the RoomID of ForEachLoop blueprints are “Not in Scope” when tracked with Watch this Value.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b9532c9a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b9532c9a](https://forums.unrealengine.com/u/anonymous_user_b9532c9a)\
**Post date:** [September 21, 2015, 5:45pm UTC](https://forums.unrealengine.com/t/getter-node-necessary-to-avoid-scope-problem/331978/6 "2015-09-21T17:45:14Z")

</div>

Can you send me a sample project that is experiencing this error? I’d be happy to take a look and see what may be occurring.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b9532c9a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b9532c9a](https://forums.unrealengine.com/u/anonymous_user_b9532c9a)\
**Post date:** [September 25, 2015, 8:30pm UTC](https://forums.unrealengine.com/t/getter-node-necessary-to-avoid-scope-problem/331978/7 "2015-09-25T20:30:47Z")

</div>

Hi Shrooblord,

We have not heard from you in several days. I am marking this thread as answered for tracking purposes. If you are still experiencing this error, please comment back with the requested information.

---

<div class="post-metadata">

**Author:** ![Shrooblord](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shrooblord/32/88712_2.png) [@Shrooblord](https://forums.unrealengine.com/u/Shrooblord)\
**Post date:** [October 3, 2015, 11:12pm UTC](https://forums.unrealengine.com/t/getter-node-necessary-to-avoid-scope-problem/331978/8 "2015-10-03T23:12:16Z")

</div>

Sorry about that. Haven’t found the time to recreate the problem in a sample project. Will do this in the next couple of days. Can I find you on the forum and send a project to you there, or should I post a download link here?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b9532c9a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b9532c9a](https://forums.unrealengine.com/u/anonymous_user_b9532c9a)\
**Post date:** [October 5, 2015, 3:06pm UTC](https://forums.unrealengine.com/t/getter-node-necessary-to-avoid-scope-problem/331978/9 "2015-10-05T15:06:44Z")

</div>

It would be best to post it here if possible. If privacy is a concern, however, you can send it to me in a private message on the forums (same user name).
