Map Variable, add Keys and Values

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
XY-Array

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

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.

image

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

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?

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

2 Likes

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

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.

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

Screenshot 2022-06-12 171254

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:

Sorry for the bad wording

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 :sweat_smile:

1 Like

Thank you for pointing out the badness of my practice!

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.

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

5 Likes

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


into blueprints. C’mon Epic!

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

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
image

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.

1 Like