Different shapes of array.

Hello, I’m aware how to create basic rectangular or box arrays. But i’m having trouble creating other shapes.
Is it even possible, for ex. recreate this:

i got two ideas :
Easy one but boring: Use your square grid and create an array with indexes to ignore when instancing / spawning or indexes to spawn, depending of number of spawned / number of indexes. It needs to prepare the array and not mistake values ignored.

A bit more fun : Spawn your grid line by line with an array of ints and an array of transform. for each line you do a loop (so a loop of loops for whole grid) from 0 to last index of int array you spawn items to the value of int, using the value of int array as index for first transform spawn location. array will not be redundant like that but it will need entries not used. maybe you can use the index too instead of value and set each transform as you need.

It is definitely possible but you will be looking at some more complex algorithms to figure it out. I remember doing a similar thing back when I was first learning C++ back in University.

Yep, I love working on games that are generated, and as such I have needed arrays to be rectangular & such, I haven’t done a circle, but it wouldn’t be too hard. I have been working on a temperature system, naturally; temperatures spread in a circular motion. While I am still using a square array, only indexes within ‘the circle’ are affected by the heat source.

So basically you can pre-determine how many indexes are on each row/column, so you should make a curve float that corresponds to this. Time should be the index, and value should be the row/column. This should only take you 1-2 minutes for the circle you put in your picture above. For a bigger circle, just multiply some values to get what you want. Now make another curve float, time should be the row/column, and value should be how many indexes that row is indented. So the 1st row is indented 3, while the 4th row is indented 0. Now make just 1 more curve float, time should be the row/column, and value should be how many indexes fit on that row/column. So row 1 should be 3, and row 2 should be 5. Now using these 3 curve floats, you should be able to get the row & column of any index. So index 4 would be the 2nd row, and the 3rd column. Just plugin your index to a get float value of the 1st curve float, using that return value, do the same for the other 2 curve floats, and using a little bit of math, you can figure it all out. It’s really quite easy, I’d love to explain more but I am tired, and it is late. Either someone can explain what math to do once you have the values from the curve floats, or I can explain in the morning, just ask and I can answer. This is probably the easiest method there is, hope I have helped, and can be of more help if needed :slight_smile:

Thanks for all your replies.
Firstly, I’m happy that I had the same ideas, as you are, guys.
Secondly, I’m a bit disappointed there are no other ways:)
Nevertheless, I’ll try every idea.

Hey Konargus,

If you are using blueprints I believe they only support 1 dimensional arrays where as you have a 2d image there. If you are using C++ I believe it supports 2d Aarray.

It is possible to create the effect of a 2d array with a 1D array, knowing your X dimension and your Y dimension, eg, 5x3 you would have 15 indices in your array (or 0-14) and with some simple math you know 0-4 is row 1, 5-9 is row 2 and 10-14 is row 3.

Knowing the index of the cell above you is minus the X dimension, eg. you are at index 8, the cell above you is 3 (8-5=3). The opposite for cells below you.

Knowing the cell left or right to you is either adding or subtracting 1 from you current index.

To create your image above some would be blank and some would be filled. Then offset each cell index by however big your asset is.

Hope this makes sense. I know it works because I have done something similar and is very effective.