# Procedural Mesh Generation on Z Axis

Hello,

I followed along with the LiveStream where they were building an X and Y grid procedurally using InstancedStaticMesh components. I attempted to build the “pillar” section out of the shape_cube item, but I wanted to be able to stack the cubes 2 high (or any arbitrary number).

My real goal is to generate a cube from a series of smaller cubes given the number of X,Y, and Z. But I’m having a problem with the math of it all. I can’t figure out which operation I need to conduct to apply to the Z field of the MakeVector function to get the proper results. I’ve had results that generated series of stairs, results that just added on to one of the other two axis’s, etc, but nothing that simply generates a cube exactly on top of another cube across the entire surface up to the specified height.

What about after I apply the X/Y transformation I have another branch statement that says "IF ArrayElement > (MaxX * MaxY) then (TotalArrayElements / MaxZ) % MaxZ. Then multiply that number by TileSize

Would that work or am I way over thinking this?

Success! Eureka!

After many various attempts, I concluded the best way to go about this was to create a separate array that would handle the various “layers” of the cube (since the X/Y math worked fine on it’s own). The problem had been that for elements in excess of (MaxX * MaxY), the element math was spawning the new cubes outside the bounds of where they should be.

The solution was to create an array (NumLayers), and resize it to MaxZ. Then, run the ForEachLoop, and in the main body of that loop have a second ForEach that took the NumLayers array and multiplied the index by ZoneSize (the size of the mesh tiles). This value was plugged into the Z coordinate, and creates nice cubes. The only (slight) problem would be that if you plug in 0 for MaxZ, you get no cube, but to me this is more a feature than a bug because if you have 0 layers you have nothing anyway.

Thank you for the answer, when i tried figure it out, it made stairs.