# Get a variable by a string?

**URL:** <https://forums.unrealengine.com/t/get-a-variable-by-a-string/627393>\
**Category:** Blueprint\
**Tags:** unreal-engine, UE5-0, question, Blueprint\
**Created:** [August 12, 2022, 10:58pm UTC](https://forums.unrealengine.com/t/get-a-variable-by-a-string/627393 "2022-08-12T22:58:14Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![PuppyPooper](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PuppyPooper](https://forums.unrealengine.com/u/PuppyPooper)\
**Post date:** [August 12, 2022, 10:58pm UTC](https://forums.unrealengine.com/t/get-a-variable-by-a-string/627393/1 "2022-08-12T22:58:14Z")

</div>

I am trying to make an array of arrays to make a table. (I couldn’t find anything to make an editable table if you know something pleeeeeease let me know)

I am trying to loop through all my arrays (height0, height1, height2, …) but I cant find any function to get an array based on a string.

In my blueprints I loop thought and append the index to string “height”. I want to call the variable by that string, I don’t know if there is a better way.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/f/6/7f63aead431b3905d1b025fa8efead26d20a5c8a.png)

---

<div class="post-metadata">

**Author:** ![dorusoftware](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dorusoftware](https://forums.unrealengine.com/u/dorusoftware)\
**Post date:** [August 12, 2022, 11:07pm UTC](https://forums.unrealengine.com/t/get-a-variable-by-a-string/627393/2 "2022-08-12T23:07:09Z")

</div>

you can try looking into Data Tables.

also if you got to the marketplace tab then click on Free then on Free for this month you will find an assets that let’s you work with MySql if this is something you need for your project

---

<div class="post-metadata">

**Author:** ![eblade](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eblade](https://forums.unrealengine.com/u/eblade)\
**Post date:** [August 13, 2022, 5:08am UTC](https://forums.unrealengine.com/t/get-a-variable-by-a-string/627393/3 "2022-08-13T05:08:13Z")

</div>

definitely datatables are good to work with if you want a table 🙂

---

<div class="post-metadata">

**Author:** ![L.F.A](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l.f.a/32/1194525_2.png) [@L.F.A](https://forums.unrealengine.com/u/L.F.A)\
**Post date:** [August 13, 2022, 5:19am UTC](https://forums.unrealengine.com/t/get-a-variable-by-a-string/627393/4 "2022-08-13T05:19:20Z")

</div>

Hi there,

I believe you want something like this.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/a/3/aa3cde0e1fc4ad15e32364ed17cfcf18cea14c13.png)

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [August 13, 2022, 5:49am UTC](https://forums.unrealengine.com/t/get-a-variable-by-a-string/627393/5 "2022-08-13T05:49:24Z")

</div>

> [@PuppyPooper](#):
>
> array of arrays

TArray\<TArray is not supported. A Datatable is not editable, it is read only. Getting a value by a “Key” such as a string is done with a TMap container.

> **[TMap](https://docs.unrealengine.com/5.0/en-US/map-containers-in-unreal-engine/)**
>
> TMaps are primarily defined by two types — a key type and a value type — which are stored as associated pairs in the map.

---

<div class="post-metadata">

**Author:** ![NightHawk45](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NightHawk45](https://forums.unrealengine.com/u/NightHawk45)\
**Post date:** [August 13, 2022, 6:52am UTC](https://forums.unrealengine.com/t/get-a-variable-by-a-string/627393/6 "2022-08-13T06:52:14Z")

</div>

Unfortunately I do not believe what you are trying to do is possible using blueprints. You cannot access a variable using a string. You need a reference to that variable. I have two possible workarounds for you to try though:

1.) Make a structure containing an array of ints. In your bp, create an array of those structures. This used to not work, but the bug report is marked as “could not reproduce” so it may work now. (UE-11171)

2.) Combine your arrays into a single array and use indexes to mark boundaries.

---

<div class="post-metadata">

**Author:** ![NightHawk45](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NightHawk45](https://forums.unrealengine.com/u/NightHawk45)\
**Post date:** [August 13, 2022, 7:04am UTC](https://forums.unrealengine.com/t/get-a-variable-by-a-string/627393/7 "2022-08-13T07:04:18Z")

</div>

> [@Roy\_Wierer.Seda145](#):
>
> Getting a value by a “Key” such as a string is done with a TMap container.

You can only map a key to a single value, so this wouldn’t really help.

---

<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:** [August 13, 2022, 7:44am UTC](https://forums.unrealengine.com/t/get-a-variable-by-a-string/627393/8 "2022-08-13T07:44:50Z")

</div>

Map a key to a struct and Bob’s your uncle.

---

<div class="post-metadata">

**Author:** ![Ares9323](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ares9323/32/1194521_2.png) [@Ares9323](https://forums.unrealengine.com/u/Ares9323)\
**Post date:** [August 13, 2022, 8:49am UTC](https://forums.unrealengine.com/t/get-a-variable-by-a-string/627393/9 "2022-08-13T08:49:03Z")

</div>

Create a struct that only contains an array of your desired class (in this case I used Actor)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/0/0/700e051826729597454296845e4fb2164d9e28ff.png)  
Create a Map with String as Key and your struct as value  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/a/7/7a720ff92de31f07dc2d43b26bf477b4af49c5ff.png)

When you add a value to the map if the name already exists it gets replaced

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/4/1/b4182644b71dca29681997fd312bfa8f9bf72160.png)

To read all the values from the map you can iterate through all keys and use the find function:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/e/3/ae3cc576ab3579a257a2b7320a9188104e4efe3c.png)

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [August 13, 2022, 8:52am UTC](https://forums.unrealengine.com/t/get-a-variable-by-a-string/627393/10 "2022-08-13T08:52:12Z")

</div>

that is OK , same way we do it in c++ when TArray nesting is not supported. Just a struct wrapper.

---

<div class="post-metadata">

**Author:** ![dorusoftware](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dorusoftware](https://forums.unrealengine.com/u/dorusoftware)\
**Post date:** [August 13, 2022, 11:37am UTC](https://forums.unrealengine.com/t/get-a-variable-by-a-string/627393/11 "2022-08-13T11:37:10Z")

</div>

unreal has already a way to access data using text as input.

You can do this using Primary Data Assets, which are accessed by passing a “link”, “string” with the location of particular data asset located in the packed game data. You can then for example construct this link using strings.

This may not be what the topic of this thread is requesting, but just so people reading this may be aware of this option
