Map with Structures by-ref


I have a map that contains structures as values for quick access via IDs. In my tick, I need to update all structures. Therefore I create a For Each Loop that iterates over all values of the map.

Now I notice that this has no effect because the structures returned by the VALUES node are copies of the structures in the map. Whyyyyy would Epic do this? Why are structures not used by-ref as a default and only cloned when specifically requested? Not only makes this the blueprints needlessly more complicated, it is also slower. Whyyyy?? I want to understand why anyone would build it in this way.

1 Like

Especially that Get does come in 2 delicious flavours!

Structs are treacherous in BPs :frowning: You generally copy so much data… So easy to lose things.

1 Like

Man, it’s so bad. I don’t get how you can build such a nice visual coding language that abstracts everything and then they don’t abstract this super basic behavior that is standard in every single programming language except C/C++.

May have something to do with this:

Btw, you can modify it to be a reference, like so:

Shouldn’t, since I don’t want to reorder or manipulate the array, only the content of an element.

I think the reason is because structs are passed by value by default in C++. There are more problems related to this, not only with Maps / Array. For example you can pass a structure parameter into a function and mark it to be passed by reference. However, if you store that structure parameter in a local variable in that function, the reference is lost and all changes to the structure are on a copy. So you can’t store it in a temporary variable, and instead you have to drag the original parameter pin all over your function if you want to make changes to the reference. That’s just… sad. I haven’t found a way to save it by-ref in a local variable, it’s always a copy.

1 Like

Passing empty array by ref:


And its length is 1 after:

Function pins automatically create local variables, no need to drag anything around.

1 Like

Ah, I didn’t know that it creates local variables automatically, that’s nice!

It is until you think of doing this:


And hey, great but then you try this and:

The rabbit hole goes really deep here. I have a love / hate relationship with structs in BPs. I’ll try to dig out my old post and link it here.


Pretty useless with half the images missing due to forum update shenanigans:

1 Like