# Why is  my variable not in scope?

**URL:** <https://forums.unrealengine.com/t/why-is-my-variable-not-in-scope/475355>\
**Category:** Audio\
**Tags:** variables, error-code, scope, unreal-engine, loop, question\
**Created:** [December 3, 2020, 11:32am UTC](https://forums.unrealengine.com/t/why-is-my-variable-not-in-scope/475355 "2020-12-03T11:32:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shedels](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shedels/32/1121823_2.png) [@Shedels](https://forums.unrealengine.com/u/Shedels)\
**Post date:** [December 3, 2020, 11:32am UTC](https://forums.unrealengine.com/t/why-is-my-variable-not-in-scope/475355/1 "2020-12-03T11:32:30Z")

</div>

On this pictures i’m creating the buttons in my gridpanel and i have the Index var.  
Next i get this index and text from rich text block and it is not in the scope!  
Can you tell me how to fix it?

 ![323759-12211213.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/9/f/b9fd6bf287400d28baed127e77877e3cb303c95a.png)

 ![323760-32323323.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/3/3/c337d335d3a9d8fa6ee034fbec3410164ed3d99b.png)

---

<div class="post-metadata">

**Author:** ![mcleary](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mcleary/32/924204_2.png) [@mcleary](https://forums.unrealengine.com/u/mcleary)\
**Post date:** [December 3, 2020, 11:37am UTC](https://forums.unrealengine.com/t/why-is-my-variable-not-in-scope/475355/2 "2020-12-03T11:37:56Z")

</div>

You probably need to step into the for each body for the variable to enter into scope. I believe this is similar to this piece of code

```
for(int i = 0; i < MyArray.Num(); ++i) {
   // Array Element is only initialized (enter the scope) here.
   auto ArrayElement = MyArray[i];  
}

```

and in the pictures you attached the debugger is at the `for` line.

---

<div class="post-metadata">

**Author:** ![Shedels](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shedels/32/1121823_2.png) [@Shedels](https://forums.unrealengine.com/u/Shedels)\
**Post date:** [December 3, 2020, 11:41am UTC](https://forums.unrealengine.com/t/why-is-my-variable-not-in-scope/475355/3 "2020-12-03T11:41:39Z")

</div>

Hello! It is always return false, so i suppose this will not help =(

---

<div class="post-metadata">

**Author:** ![mcleary](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mcleary/32/924204_2.png) [@mcleary](https://forums.unrealengine.com/u/mcleary)\
**Post date:** [December 3, 2020, 11:46am UTC](https://forums.unrealengine.com/t/why-is-my-variable-not-in-scope/475355/4 "2020-12-03T11:46:18Z")

</div>

What returns false? The comparison? How many elements do you have in your array?

---

<div class="post-metadata">

**Author:** ![Shedels](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shedels/32/1121823_2.png) [@Shedels](https://forums.unrealengine.com/u/Shedels)\
**Post date:** [December 3, 2020, 11:48am UTC](https://forums.unrealengine.com/t/why-is-my-variable-not-in-scope/475355/5 "2020-12-03T11:48:28Z")

</div>

![323775-безымянныи.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/0/a/c0a098f9ced1104a5c391f2907baa4ce80a88e85.png)

Oh, sorry, I have branch there.

---

<div class="post-metadata">

**Author:** ![mcleary](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mcleary/32/924204_2.png) [@mcleary](https://forums.unrealengine.com/u/mcleary)\
**Post date:** [December 3, 2020, 12:30pm UTC](https://forums.unrealengine.com/t/why-is-my-variable-not-in-scope/475355/6 "2020-12-03T12:30:26Z")

</div>

That’s why I asked how many elements you have in your array

---

<div class="post-metadata">

**Author:** ![Shedels](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shedels/32/1121823_2.png) [@Shedels](https://forums.unrealengine.com/u/Shedels)\
**Post date:** [December 3, 2020, 12:56pm UTC](https://forums.unrealengine.com/t/why-is-my-variable-not-in-scope/475355/7 "2020-12-03T12:56:00Z")

</div>

On the 1 pic: 32x32 loops. From 0 to 31 both arrays.

---

<div class="post-metadata">

**Author:** ![mcleary](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mcleary/32/924204_2.png) [@mcleary](https://forums.unrealengine.com/u/mcleary)\
**Post date:** [December 3, 2020, 1:59pm UTC](https://forums.unrealengine.com/t/why-is-my-variable-not-in-scope/475355/8 "2020-12-03T13:59:00Z")

</div>

Right, this was just to rule out the possibility of you having less elements in the array then expected. In that case, are you able to put a break point in the branch itself? Since the Branch is an execution node you should be able to see the variable you want in scope.

---

<div class="post-metadata">

**Author:** ![Shedels](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shedels/32/1121823_2.png) [@Shedels](https://forums.unrealengine.com/u/Shedels)\
**Post date:** [December 3, 2020, 5:33pm UTC](https://forums.unrealengine.com/t/why-is-my-variable-not-in-scope/475355/9 "2020-12-03T17:33:39Z")

</div>

If i understood you right i should try to add breakpoint. Here is the picture:

 ![323832-56567867.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/e/6/9e623fe053f2de48a881f69b23957a8adc2e3a98.png)

---

<div class="post-metadata">

**Author:** ![mcleary](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mcleary/32/924204_2.png) [@mcleary](https://forums.unrealengine.com/u/mcleary)\
**Post date:** [December 3, 2020, 6:42pm UTC](https://forums.unrealengine.com/t/why-is-my-variable-not-in-scope/475355/10 "2020-12-03T18:42:39Z")

</div>

That was my suggestion yeah, but now I have no idea of what could be wrong, sorry about that.

---

<div class="post-metadata">

**Author:** ![mcleary](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mcleary/32/924204_2.png) [@mcleary](https://forums.unrealengine.com/u/mcleary)\
**Post date:** [December 4, 2020, 9:53am UTC](https://forums.unrealengine.com/t/why-is-my-variable-not-in-scope/475355/11 "2020-12-04T09:53:38Z")

</div>

@Shedels are you able to share the project? I could try to take a closer look if you can.

---

<div class="post-metadata">

**Author:** ![Shedels](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shedels/32/1121823_2.png) [@Shedels](https://forums.unrealengine.com/u/Shedels)\
**Post date:** [January 11, 2021, 4:02pm UTC](https://forums.unrealengine.com/t/why-is-my-variable-not-in-scope/475355/12 "2021-01-11T16:02:37Z")

</div>

Got the anwer. It is because the loop has it own scope.
