Performant way to add 3D vector data to 1D array

So I’m just a designer, not much of a programmer, but I just found out that Unreal doesn’t really like 3D arrays.

Since I can’t just for loop each sub array, what is the consensus, if any, about how to add a grid of vectors to a one dimensional array?

My thinking is just to create a cycler which goes through each value in Z, resets to Z to 0 and iterates X and so on. But this is probably ridiculously over built for the purpose, no?

I’m also fine with moving the function to C++ if it is better that way.

You need structures buddy. Right click in the contact browser and choose Blueprints → Structure. You can then make an array of pairs of vectors or quads of rotators, or whatever you like :slight_smile:

( Mind you, all vectors are 3D, so maybe you just want an array of type vector?.. )

Sorry, perhaps I ought to have been more specific/clear, by 3D, I mean I have a three dimensional grid of vector locations that I want to add to an array; I read that you can do a struct in a struct in a struct to get an easily readable set of data, like a bog standard multi-dimensional array in C++ but that seems a bit hacky and slow.

I suppose if I were a mathematician I could think of a mathematical way to get all the correct values in to the array but I don’t know a formula to iterate all potential values in a cube grid and also not sure if that would be performant enough anyway.

Other option is 3 layer index segmentation over 1D array to create virtual 3d index, let say we have continues 32x32x32 3D data and so we can calculate index for 3d potion like this:


So for more universal size solution let say S is size on all dimentions


It;s a lot easier to operate this as by going thru index you will read data from other dimensions and you can go thru entire cube with single for each.

You can also try using map,

but map stores index same as data , so it not really optimal way , but if you have non-continues data (have lot of zero/null data) and just single positions in you can all store them in map and store only pieces of cube that is impotent. Only issue with Vector as key of map is that vector is a float and may have precision issues

Yes I was thinking of making a struct that is just a trio of ints that I treat as a vector. I’m not totally clear on the method but I will try and follow it and see if I get it. Eventually, I will want to be able to remove chunks from the vector map when they become used so it will get irregular over time. I think I need to do more research on how to handle this kind of data.

Sorry for the late replies, I posted them much earlier but they were being moderated. In UE4 Blueprint they show up as a bunch of floats I suppose because people are doing gameplay stuff like raycasting with it? I suppose if you were doing this in C++ you might not use the Blueprint version.

I’ve looked this up elsewhere and some people include this big solver in their projects which gathers all the possible points in a grid but I think that level of complexity is unnecessary for me.

Am I missing something here ( quite possible ), but the normal everyday vector type, already is a trio of ints…

No it is struct of floats, you can see it it’s API refrence:

It probably wont harm if you use integers only, but there always possibility CPU might butcher they key during processing by adding some odd fraction making value hard to access without looping

There different type which has vector made of integers called FIntVector, but not sure if you can use it in Blueprints, you can try to find it, but oyu can definitely make more stable map with it in C++:

It would be hard to do graphical related stuff in vector of integers.

I also notice there being new template implemented TVector allowing you to create any vector type with as much of dimensions you desire

Sorry, my bad, I meant trio of floats :slight_smile:

Ah ok :stuck_out_tongue: But in what context you talking? map? or array?

Waht i show here is to use 1D array like multidimensional array by segmenting index, ofcorse you can make a function that will read out the array based on inputted vector

I was talking array.

I generally find that when using these different ways of trying to represent ideas ( whether is be by segmenting index or using structures etc ), some parts of the code become very elegant, but other parts can end up being much worse…