[Request] 2D Arrays

Can we get 2D arrays added to blueprint? I had seen discussion on this in the past but I can’t find the post.

I have generally worked around the need for 2D arrays in blueprint but the deeper I go the more I am wishing I had them.

I have seen a little info bit about data tables, but I am not sure if they are supposed to be our solution in the place of 2D arrays, or if there is another option besides creative use of normal arrays. Additionally, from what I have seen, they aren’t fully operational for blueprint use at this time anyway.


Hi Zeustiak,

This is something I have been looking into and have been very interested in getting in the engine. For now, however, I have a way to manually create a 2D array. Check out the image below. Basically what I did was create an array of arrays by plugging a get array into each array slot. Then when I need to update I have individual int’s for both “rows” and “columns” that are updated independently of one another. I’ll have more details out once it is a bit more polished.


Great to hear! :slight_smile:

I figured you could approximate a 2D array using normal arrays, though I will admit I am not even sure what is happening with the blueprint you posted… :stuck_out_tongue: Maybe I am a little confused about why you have 4 gets instead of 2, but I think if I saw how you set your Ints and Array 1 1/1 2/etc it would make more sense.

Either way, I look forward to seeing 2D arrays become nodes in the future and appreciate your response. I may or may not use a workaround in the short term. I will have to see how badly I need it to implement a few of the systems I am working on.

Hi Zeustiak,

Well, in my case I’ve expanded on the idea a bit. I am currently attempting to build an NPC dialogue system using nothing but blueprints. So here is the section where it chooses which array to select your answers from to prompts based on what you have previously selected. Currently I’m up to 12 arrays and haven’t had a chance to set up the prompt array yet for it to choose what the npc says.

Here is how I approximated a 2D array in order to implement a system to store groups of tiles for landmasses and bodies of water:

So the above starts with 1 tile index from map in the Open List. Then I neighbor check his 6 neighbors and each neighbor sharing a tile type gets added to the open list. This continues until each like tile in the landmass or body of water is put into the closed list. When that is complete I dump the closed list into an array and add 100,000 multiplied by the multiplier. The multiplier starts at 1 and increments by 1 every time the closed list gets dumped. So the first lake would have tiles that look like 1XX,XXX, the second 2XX,XXX, etc. The reason I use 100,000 is because the upper range for map indexes is over 10,000, and the highest number is what I use to track which lake I am looking at.

With each lake serialized into an array I need a way to retrieve that information:

I have Current Index which is whatever tile I want to look at. I go through my entire Water Body Array, divide it by the 100,000, and match the remainder to my Current Index. Then I know I have the right lake, so I set that to the Current Landmass/Body of Water for use in:

Since I now know what lake I am looking for, I use that info to pull all the tiles of that lake from the Water Body Array and dump them into my Lake Array.

Would love to see how you are handling it now, or if you have any ideas to improve my method. :slight_smile:

I can probably get by without 2D arrays, but I think they would be at least somewhat more performant than doing 6 digit math potentially tens of thousands of times. :slight_smile:

Hi Zeustiak,

Unfortunately I haven’t been able to work on it much recently. I will try to look into it on the next Epic Friday and see what I can come up with. I’m really impressed with your work so far!

Thanks. Look forward to seeing what you come up with! :slight_smile:

I remembered that you can put Arrays in Structs and then those Structs into a Struct Array. I updated my system to use that and it works about the same.

It is a little bulky though. Perhaps that kind of setup could just be combined into a single node/variable for a 2D array? The input and output would each have 2 indexes; 1 each for row and column. Anything having anything to do with the 2D index(add, get, etc) would take 2 index inputs for row and column.

Anyway, thanks!

I really like that idea. It would be a great addition to be able to create a 2D array without having to subvert the system to be able to do so. I’m going to pass this along to be assessed by the development staff!

I’ve typically used a 1D array with support functions for offset lookup rather than using jagged arrays.

Can you explain that further? I have to generate and work with 10+ times 10+ 2d arrays and Adams solutions does seem like a lot of work for that, besides from having a set size.

Basically, you need three functions:

Here, our 2D array is stored row-major, with rows being the number of rows, and columns the number of columns. X, Y are the row, column coordinates respectively, and idx is a 1D array index. You can implements these in C++ or Blueprint (the last function you’d either want to return a struct with the X,Y coordinates, or split the function into two, one for X, one for Y).

Make2DArraySize(int rows, int columns) { return rows * columns; }
Get1DIndexFrom2D(int X, int Y, int columns) { return X * columns + Y; }
Get2DIndicesFrom1D(int idx, int columns) { return (idx / columns, idx % columns); }

A few weeks ago i implemented a 2d array.
It has an enum input, to tell the array if you want to create, get or set something.
The dividor just converts unreal units to meters - ignore it.