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

See:
https://www.fab.com/listings/0e7a487e-dae5-4542-bafb-17a927df350b

Not only that this is an old post, you are posting a link to your paid fab library…

Here is what anyone can do for free:

Use the find node to get your value based on the required key. Make changes to that returned value and then use the node “Add” with input the map and same key, and value what you just edited at the last step. This will not add a new value, it will simply replace what was in the map as you are using the same key.

This is the content of the “Set Aux” macro used above:

I use this macro especially when I create a random value and I want to use that value in multiple places, not be changed and not having to store it as a variable or local variable in case of a function, as if you take the output from random function, it will return a different value each time. I made the input wildcard so I can use it for almost any type.

image

AAAA is a simple structure with an int array

The sequence (part of the engine) is nothing special, I used it to order the blueprint better so it all fits in the screenshot, what it does it runs each execution pin in order.

As you can see, the order of the keys didn’t even changed, only the value of the key 1.

Now returning to your post, on top of not being free, your function is restricted to a Map of key String and value Vector, it wouldn’t even work for my original question.

image

Not only that, but how is it “Open-Source code” when you don’t include a link to the code, and it is a paid function. If it is open source you should have a link to the code, and it should be free.

What is even worse then that:
image

So even if I would have wanted to use it, I couldn’t…

The find(ref) function in this plugin accepts wildcard parameters and works with any map type.

The root cause of your original question is that the default find function returns a copy instead of a reference. Your “modify-then-reinsert” workaround is indeed a compromise—it solves the problem but introduces many extra nodes, reducing readability and hurting performance.

I also noticed that the default Blueprint implementation of find doesn’t have a reference-returning version, and I couldn’t find a plugin with similar functionality in the Fab either. So, I implemented one myself, which took me quite some time. That’s why I’d like to sell it for a small fee.

I had hoped to help you, but unfortunately, my trader verification is still pending, so I might not be able to sell in the EU region for now. Sorry, my plan didn’t work out—just pretend I never replied.

My mistake then, from your screenshot it doesn’t look like that is a wildcard.

In my example it only adds SetAux and Add nodes, the rest are just modifications of values which you would add in any way you solve the problem, and also parsing the Map. No other nodes are extra beside those 2. So it doesn’t affect readability, as for performance yeah, you could say it can hurt it, but you would have to use it on a really large number or values, else it is unnoticeable.

From what I understand they don’t return a reference so that you don’t accidentally change the value, forcing you to do something similar with what I said so that you are sure you want to change those values.