Blueprint Map "find" node that gets value as reference possible? Same as "Get (ref)" for arrays

Right, I’ve been checking this stuff lately and realized that, so it’s not possible to “return” values by ref with a plain UFUNCTION even with CustomThunk, you’d probably need a custom K2Node. The thing is that I’ve also checked how the Array Get node does this, and… It’s kinda annoying because from what I’ve gathered it’s deeply buried within the engine’s blueprint compiler code.

So, you need to use a K2Node, but you gotta code your own NodeHandlingFunctor and write the whole process as if it was assembly language.

But wait, there is more. Since the NodeHandlingFunctor still relies on UFUNCTIONS for custom actions, you can’t actually do the thing anyways. The actual by-ref assignment seems to be done by the compiler itself, which specifically targets arrays. I haven’t been able to follow up from there but I’m sure it isn’t possible without modifying the engine source.

Wouldn’t that technically be the same as the Map Set node? We want the ref so we can work with specific map entries without having to be calling that function anytime we do changes to them.

This would be particularly useful when you’re also working with data nested within structs or several levels of map abstraction.

For example, I’ve got somewhere an object with a property containing a map of structs. This struct type contains two arrays, which isn’t even too complex compared to some wild sh*t that I’ve seen in the actual engine code.

At the moment, to modify these arrays I gotta:

  1. Do a Map Find.
  2. Copy the value in a local struct variable.
  3. Copy the struct’s array in another local array variable.
  4. Do an Array Get.
  5. Set the local array’s element.
  6. Update the local struct variable with the modified local array.
  7. Update the map with the modified local struct.

Imagine now you gotta do this on a loop. In the other hand, if I could access the data by ref I could just:

  1. Do a Map Find.
  2. Break the result and do an Array Get.
  3. Set by ref.

Even looping, it would simplify a lot of work here.

In the end, what I did to get around this (in what is probably a very hacky way) was to make a struct that contains a pointer to the property and a raw pointer to its value, and pass it around as if it was the value by ref.

Then I made some variants of the array, set and map functions, but which return this struct instead of the actual value, pointing to the element I want to retrieve/modify.

Finally, I included a function to get a copy of the struct data, and another to set the pointer’s values under the hood.

They probably aren’t very safe, but hey, somehow they work and my computer is still in one piece.