Download

working with flattened 3d arrays in BP

hey everyone! UE4 newbie here!
I’m trying to build my first blueprint (trying to make a flattened 3d int array for a sort of random dungeon generator) so I started with this video as my reference Blueprint Generating Procedural Rooms | Live Training | Unreal Engine - YouTube and I managed to do this


which got me a nice cube made out of cubes
my problem is that I am terrible at math and I’m making the flattened 3d array version of those cubes with random examples I found on the web. I think I found the algorithm (not entirely sure it is right) for indexing the cubes in the array
but now I need to get the XYZ just with the array’s index and here’s where I get lost :frowning:

so if anyone could point me to any examples or just throw any advice I would greatly apreciate it!

I don’t have time to figure out the algorithm right now, but I’m pretty sure that you will have to use 2-3 “Division w/ Remainder” nodes, the int return value will give you the X/Y/Z.

Thanks a lot for the quick reply, I’ll look up the division node and see how it works!

Using the Division (whole and remainder) node, you can get your x, y and z coordinates for index i as follows:
z = i / (x*y), which leaves remainder r1
y = r1 / x, which leaves remainder r2
x = r2

Yep, that looks about right.

Well, it appears that the Division (whole and remainder) nodes require floats, so you’re probably better off doing it by hand to keep integers all the way.
I attached a picture showing how I did it, without checking for the validity of the index.

Just got back from work, tried it and it works! thanks a lot for the help!