Is there any way to set a map element specifically?

So like an array, is there a way to set a specific element in a map using two values of the same variable type the map contains? Because the “Set Map” node doesn’t have an option to choose an element. And unlike arrays, there’s no node that sets the array element by array reference, and you can choose the specific element you want to set depending on the variable type of the array (i’m bad at explaining). Is there any way to do the same with maps?
image
image

1 Like

So, do you want to update an existing key inside the map variable? Have you tried to use the Add Map node? It serves both ways, to add and update values. If the ‘key’ already exists, it will update it. Else, it will add a new key.

4 Likes

Thanks! I knew that was there but i didn’t know you could use it to select a map element.

1 Like

Wait… I think I’ve misunderstood
I wanted to set a specific element in a map, but in the set node there wasn’t an option to enter an element, unlike arrays. So what I didn’t notice in the image you sent was that the integer variable was part of the map. So now I’m confused.

Hi there, this is just an example. Try with your map variable. The map variable can have multiple types of variables assigned as keys or values, including struct variables with multiple elements.

Yes I am aware. However, my problem is I can’t seem to set a map element as you would do with arrays, even though in the default value section, it specifies them as “Map Elements”, and I want to choose an index to set in the map instead of choosing a whole map value to set the target map to.
image
image
As shown in these images, there is an integer value before “Map Elements” or “Array Elements”. What I’m trying to imply here is that there is a node for setting specific array elements, but not for setting map elements.
image
image

Add is the node. You can’t have two elements with the same key, so ADD is used to update.

1 Like

‘Add map’ node is the correct way, otherwise you may need to get all this done with value arrays. I have never used another way, by-the-way.

1 Like

Ohhhh. Thanks for clarifying!

1 Like

I understood him a little better becuase im currently doing the same thing…he has a map with an array and only wants to update a single value in the array…if you used “ADD” what exactly are you adding? hes trying to target a single array member in the values…not the whole thing…the user LFA below is more correct as to what he was looking for…tho they posted exactly what the user said he already tried…FIND node pull the exact array, no need to iter through them…but set array elem does not actually update the value in the map…this is the problem both this user and i are trying to solve.

It is possible, but it’s a total mess

I know conceptually, it’s a nice idea to get all your data structures organized, but I’d either keep all these things separate ( as parallel arrays ), or use CPP.

For sure, “Add map” node is the correct way. If the entry key doesn’t exist, both key and values will be added. Else, the key will be the same and its values will be updated.

what i ended up doing is find the key, then set the value to a local variable array, I set element by ref in THAT local array, then i add map with the original key name and the local array. sucks that we have to jump through an extra hoop to accomplish this…and that theres no warning that normal methods dont work. unfortunately even clockworks method, which at first appeared to work, did not work for me with object refs in an array. might work with vectors or standard variables, but not objects/actors.