Array of structs or actors in blueprints?

Unreal Engine is missing any sort of a hash table in its blueprint visual programming. Closest thing is an array of structs which can be quite surprising at some moments.

A struct is an easy way to pass around bunch of a variables bundled to one small package. For example in our case we are working with a tile position which always consists of two integers X and Y or we have a object representing game setup with various data. I am not going talk about a structs in detail here. I am sure you can find better tutorials for that.

An array of structs can be used to store multiple instances of same struct with different values. However there is a huge catch that made my head spinning for a while.

How to change values in array of structs

Anytime you call a Get node on an array of structs, you always get a copy of what’s present at that index. With primitive values like strings or numbers it’s alright. However getting copy of struct instance does not help much if you need to modify that struct. Even though you can see that Set members node is expecting reference to a variable, it will get a reference to a copy that was made like this. To make the actual change you need to call Set Array Elem with newly modified struct.

To actually see that I am not making things up, here is a little debugging snippet on how to print values out of that array easily. Try to call this without the Set Array Elem node first and then plug that in to see a difference.

Debug content of an array of structs