Multidimensional Array with structs and filling it (Blueprint only)

Hello community,

iam working on a tile based game and created a multidimensional array for the grid.

Grid Array Master = Z-Axis (Amount of floors)
1.Dimension = X-Axis
2.Dimension = Y-Axis
3.Dimension = tile definitions
4.Dimonsion = more precise tile definitions

If iam filling in some data in the editor in the details panel of the coresponding blueprint, all is working well.
But if iam trying to create the GridArray per blueprint, the result is somewhat wierd.
The creation process does resetting the grid and generating the floors, but nothing more.

In this test scenary, iam generating 2 floors, so:
The GridArrayMaster only consists of Index 0,1 (without any content).

This is how i had done it.
36e1a692b3ba443469e8a1416e5ebb598f8ab827.jpeg

What am I doing wrong?

If I remember correctly - I had a similar, if not the same, problem. Strangely enough, iterating through Structs using a ForEach loop does not seem to work. This link (to the UE AnswerHub) shows the issue I was having, which sounds similar to yours, and documents a workaround.

If this is not what you are experiencing, could you elaborate on what the difference is? Also, what is your engine version? I think this might have been fixed in 4.9, but am unsure.

Iam using Engine Ver. 4.10.1

Indeed. Iterating through this seems to be the problem. But only for writing!
Reading the actual iterated element of the array is no problem and currently working (following picture).

8dd722121b1533688275c0f49cc79ce4d78e8b9d.jpeg

The next picture is showing a gap of the whole array (in editor).

Right now, iam assuming switching over to c++ to get off the problem?!

1 Like

hmm… iam not pretty shure how the “break” Command for a struct works. Iam having a feeling, that this is my problem.
Iam breaking off the whole array iterativly, but never use the “make” command, to put everthing together again.
But i have no idea how to include the “make” command.

Your images are teeny tiny so I cant really say for sure whats going on.

But I am 99% sure that your problem is the same thing I ran into. When you do “get” on a struct from an array, it returns “By Value” , not “By Reference”. So you are manipulating setting on a copy.

There are plans to fix this in code at some point but the plans are not concrete yet.

For now I have a workaround which is to recreate a new Temp array, and add each of the things you want to set into this array one by one. Then after the loop is done doing that for everything, you can do “set” on either the entire outer, or whole array depending on case. It is a bit of a pain but it is the only workaround I know for now. If this is sounding very confusing, I can try to dig up an example image.

Here I found this from an email thread.

The bottom red comment box does not work, since the “struct” reference from the “Get” is actually a value not a reference. It is very misleading though because the “struct ref” pin even has the ‘by-ref’ diamond shape. But for that to work, a reference needs to be connected as well.

In this case I just re-make the whole struct element and do “set element” individually. If you need to do this nested, you may need to rebuild the entire sub array first using a temp array as I said above.

Thanks for your answer. That sounds like it is the reason of my problem.
But i cant click on your Attachment (“Invalid Attachment specified. If you followed a valid link, please notify the administrator”).

Hmm… iam using “get” on an array filled with structs. After that iam using “break” on the “array element” pin of a foreachloop. I can only imagine that the loop uses “get” in background too.

Finally i got it. And you were right!
Recreating the array was the trick.

Could you explain this workaround a bit further? I’d appreciate it greatly.

I’m trying to figure out arrays of structs and how to correctly break them to get the information from them so this could be useful.

Unfortunately RyanB’s screenshot doesn’t work.

So in the blueprint where I want to break the original structure variable (from an array of structures which I get with foreachloops) to extract information, I need to create a new identical structure array variable and apply all the entries from the original one to this new one before breaking the new one? Or am I way off?

Or was using the make command the solution you used in the end? How did you set it up?

Hmmm… i tried to get both in one screenshot. Remember that iam creating a tile based game, so that my comments are related to that!

First, iam breaking through every element of the array (“Get through the GridArray incrementally”).
After that, i recreate each element, beginning with the tinyiest (“Recreate Y-Axis”).
Every recreated element will get stored in an temporary array (eg. “Temp2D-y-axis”).
These Temp. Data is the basis for the elements of the next step (eg. “Recrete x-axis”).
Just repeate the steps, till the last stage, where alle the temp arrays get the content of the original array (“recreate floors”).

With those steps, i have broken down through the whole array and did recreated it completely WITHOUT altering any element, but this will be next:
The upper comment box (“Check if actual tile is the searched one”) will look for the element, what will be altered.
If the position is reached, the normal recreation process will be ignored for this step and an alternative one is used (“alter tile with fiven information”).

Glad i can help :smiley:

Something got cut up:
At Input: “NEW Tile Definition”
And on the right side; the “set array elem” is the last used function (Compare with “recreate floors” eg). There is nothing more.

PS: The images are in FullHD Scale. So either download them or open them in a new window, to watch them at full size