Value not added into Array

I made a Map which contains an int for key as index, and a Structure as value. The structure has as elements an Array of a different structure and a reference to an object (in example I changed that to a bool, as I don’t have the class in the test project). The structure from the array has a boolean, two strings and an int as its members.

Now when I call Map->Add (from Blueprint) it does add a new value with the index that is given and the rest I’m leaving as null/default. The problem that I have is when I call Map->Find it does find the value for the given index, but then I want to add new values into the array, but when I call Array->Add, those values aren’t added.

Here are some images for a better picture of the problem:

This is the Map:

image

This is the Structure that is set as the value for the Map:

image

This is the Structure that is used for the values inside the array from above:

image

And this is the test to add values into the Map and then into the Array inside the Map for key value of 1:

After the 2 calls to add values inside the array, I’m calling a For Each Loop and printing the values, and when For Each Loop is done, print the size of the array. But the array has a size of 0, even tho I called add two times before it.

Why aren’t those two values added into array, and what should I change?

Hi Valentinvis,

The “Find” node returns a copy rather than a reference - so it’s not actually adding those items to the correct array.

Then there is no way to change the values of a key once it is added? I don’t see any other function I can use, and it is dumb to not have one. Other then what you linked, which as he said is a “hack” rather then “solution”.

If that is the case, I have to come up with a different way to achieve what I need there…

Yeah, adding the values into a copy which is not used later would explain the behavior.

Thanks!

Try something like (make a function or something):

For my case I changed the Map into an Array of Structure (in above example that would be of “TopLayer”), and inside the structure I added an int to act as the index from the former Map.

Like this I can get a reference from the array when the int/index from the structure has the value is given, and add into the array with that ref.

There is no need for a Map anymore that way. I wanted to use that as I would have had a better structure for the code, but it is fine this way as well. In my case I’m not working with huge amount of data, so the speed of Map->Find wouldn’t be that much faster then going through the array with break to actually notice anyway.

Thanks for your time!

1 Like