# Map Variable, add Keys and Values

**URL:** <https://forums.unrealengine.com/t/map-variable-add-keys-and-values/579782>\
**Category:** Blueprint\
**Tags:** variables, unreal-engine, UE5-0, question, Blueprint\
**Created:** [June 12, 2022, 2:12am UTC](https://forums.unrealengine.com/t/map-variable-add-keys-and-values/579782 "2022-06-12T02:12:01Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tsybe](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tsybe/32/590281_2.png) [@Tsybe](https://forums.unrealengine.com/u/Tsybe)\
**Post date:** [June 12, 2022, 2:12am UTC](https://forums.unrealengine.com/t/map-variable-add-keys-and-values/579782/1 "2022-06-12T02:12:01Z")

</div>

I have a Map variable: the Key is a simple string and the Value is a structure.  
The structure is made by another but set to an array containing two integers. Images for better understanding:

![XY](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/d/b/7dba55b19c16c5b2bf90f17147c1144049725208.png)  
 ![XY-Array](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/c/b/7cbd29a51dbf61ce501b0e14fee0d535076b4944.png)

What I want to do is to add multiple Values to a Key at runtime. For example, I did it on the image:

 ![Var](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/c/b/9cbabf3b64782c1ad6b37cf1407ea73f7cbb27ae.png)

I already know how to create a new Key with a Value, but I can’t figure it out how to add multiple different Values to a single Key.

---

<div class="post-metadata">

**Author:** ![eldany.uy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/eldany.uy/32/821920_2.png) [@eldany.uy](https://forums.unrealengine.com/u/eldany.uy)\
**Post date:** [June 12, 2022, 5:26am UTC](https://forums.unrealengine.com/t/map-variable-add-keys-and-values/579782/2 "2022-06-12T05:26:37Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/9/9/1992383ce1b937ffe3098a4666237fbfa618c911.png)

you cant have multiple values in a single Key of a MAP variable

---

<div class="post-metadata">

**Author:** ![Tsybe](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tsybe/32/590281_2.png) [@Tsybe](https://forums.unrealengine.com/u/Tsybe)\
**Post date:** [June 12, 2022, 1:55pm UTC](https://forums.unrealengine.com/t/map-variable-add-keys-and-values/579782/3 "2022-06-12T13:55:35Z")

</div>

Thanks, but are you sure it’s not possible? Even if the engine allows me to do that manually? I also can get the values if I set something up.

Isn’t it duplication only when the values are the same?

---

<div class="post-metadata">

**Author:** ![BDC\_Patrick](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bdc_patrick/32/1104221_2.png) [@BDC\_Patrick](https://forums.unrealengine.com/u/BDC_Patrick)\
**Post date:** [June 12, 2022, 2:03pm UTC](https://forums.unrealengine.com/t/map-variable-add-keys-and-values/579782/4 "2022-06-12T14:03:52Z")

</div>

yes… We are sure that you can only add unique keys to a Map or Set.  
If you want to add multiple values to the same keys, you need to use an array or struct as value… Which variables are both predefined.

You could add multiple values inside a struct, that sits inside a key… Yes…  
Like  
{“Key”, Struct{int, string, name…}}

But not  
{“Key”, int, string, name…}  
Or  
{“KeyA”, int}  
{“KeyA”, string}

And that’s not a restriction of the Engine… But of the Cpp api

---

<div class="post-metadata">

**Author:** ![Tsybe](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tsybe/32/590281_2.png) [@Tsybe](https://forums.unrealengine.com/u/Tsybe)\
**Post date:** [June 12, 2022, 3:44pm UTC](https://forums.unrealengine.com/t/map-variable-add-keys-and-values/579782/5 "2022-06-12T15:44:06Z")

</div>

Yes, that part is clear to me that duplications are not allowed.

> [@BDC\_Patrick](#):
>
> If you want to add multiple values to the same keys, you need to use an array or struct as value… Which variables are both predefined.

Is the predefined simple means what I wrote before that I can set them manually but can’t change/add/remove them runtime? Or that I must set the var types like int, string, etc.

> [@BDC\_Patrick](#):
>
> You could add multiple values inside a struct, that sits inside a key… Yes…  
> Like  
> {“Key”, Struct{int, string, name…}}

I assume that should look something like this, except I have two ints inside the struct:

 ![Screenshot 2022-06-12 171254](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/e/c/0ecbb2b07726e142aad9264d5fc8a2139e12580b.png)

Reflecting on the last image from my original post, which would look like this, I guess:

{“Key”, Struct{Struct{int, int}}}

There is only one Value/Key but there are more elements inside a Value, which is what I really wanted to ask and what I want to do: add and remove elements at runtime. Unlike how I wrote in my original post:

> [@Tsybe](#):
>
> What I want to do is to add multiple Values to a Key at runtime. For example, I did it on the image:

Sorry for the bad wording

---

<div class="post-metadata">

**Author:** ![BDC\_Patrick](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bdc_patrick/32/1104221_2.png) [@BDC\_Patrick](https://forums.unrealengine.com/u/BDC_Patrick)\
**Post date:** [June 12, 2022, 5:47pm UTC](https://forums.unrealengine.com/t/map-variable-add-keys-and-values/579782/6 "2022-06-12T17:47:31Z")

</div>

If you use an array as Value… Like  
‘’’  
Map{“key”, array{int, int ,int…}}  
‘’’

You can get and add new indexes to the array and overwrite the keys with the new array value, as you wish.

Saw a really bad practice with a struct containing all variable types, wrapped with a  
an array… Like this:  
‘’’  
Map{“key”, array{struct{int,float,string…},…}  
‘’’  
Bad that is really really bad… So better create structs as value type, that absolutely fit your needs, in memory of the Memory 😅

---

<div class="post-metadata">

**Author:** ![Tsybe](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tsybe/32/590281_2.png) [@Tsybe](https://forums.unrealengine.com/u/Tsybe)\
**Post date:** [June 12, 2022, 8:20pm UTC](https://forums.unrealengine.com/t/map-variable-add-keys-and-values/579782/7 "2022-06-12T20:20:17Z")

</div>

Thank you for pointing out the badness of my practice!

> [@BDC\_Patrick](#):
>
> If you use an array as Value… Like  
> ‘’’  
> Map{“key”, array{int, int ,int…}}  
> ‘’’

Unfortunately, I can’t find a way to set the Value to an array. Where should I look for it?  
The only way I found is to use a simple structure with a variable that I set to an array container.

---

<div class="post-metadata">

**Author:** ![Chatouille](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chatouille/32/1194622_2.png) [@Chatouille](https://forums.unrealengine.com/u/Chatouille)\
**Post date:** [June 13, 2022, 10:03am UTC](https://forums.unrealengine.com/t/map-variable-add-keys-and-values/579782/8 "2022-06-13T10:03:12Z")

</div>

You can modify/update a map of arrays (wrapped in a struct) like this :

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/c/5/5c5a0b056ca3d3ce4ff78a3245ad574a2754825c.png)

---

<div class="post-metadata">

**Author:** ![AllGamesSuck](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AllGamesSuck](https://forums.unrealengine.com/u/AllGamesSuck)\
**Post date:** [January 31, 2024, 12:24pm UTC](https://forums.unrealengine.com/t/map-variable-add-keys-and-values/579782/9 "2024-01-31T12:24:13Z")

</div>

Thanks for this. It seems odd though that they wouldn’t implement this:

 ![Capture](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/6/e/86ec5413329ccef30fc9decabd87145b1fbc0947.png)  
into blueprints. C’mon Epic!

---

<div class="post-metadata">

**Author:** ![AllGamesSuck](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AllGamesSuck](https://forums.unrealengine.com/u/AllGamesSuck)\
**Post date:** [February 1, 2024, 2:29am UTC](https://forums.unrealengine.com/t/map-variable-add-keys-and-values/579782/10 "2024-02-01T02:29:30Z")

</div>

Hey, do you know if it’s possible to have an array of maps, and change values within those maps, inside the array?

---

<div class="post-metadata">

**Author:** ![good4doog](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@good4doog](https://forums.unrealengine.com/u/good4doog)\
**Post date:** [March 1, 2024, 10:51pm UTC](https://forums.unrealengine.com/t/map-variable-add-keys-and-values/579782/11 "2024-03-01T22:51:48Z")

</div>

You could make a structure of maps (MapStruct) with a name field for array search if you like. Then Embed the MapStruct in another structure (MapArray) so you can make it an array. Then loop through and use the Map Utility options to change values.

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/2/8/9284e988a1b51e36daad499324f1bb2661c4badf.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/6/f/a6fe719efb6aba5d446b8fb0d30ad59a041a841d.png)

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

With nested Structures there are some combinations of variables that you can’t use in a map so all depends what you need to do.
