Welcome.
You might benefit from a basic technique which is to break up your goal into separate simpler tasks and tackle one at a time.
this is a high level plan:
you might be able to achieve this by using blueprints or by using niagara. the latter probably is more difficult. but depending on the number of boxes you’re spawning niagara will probably be much more performant.
depending on how you do the up/down movement you could also (ab)use the world-position-offset on a material, that can be more performant, but would have issues with collisions and not sure how well it works with nanite and lumen.
in bps you can add a variable of type mesh, then set it as array. then add 3 elements and set them to your meshes.
have a function to generate all the positions and store them in a array of vectors.
probably call on begin play.
and have a function to do the spawning, probably called after generating the points.
in that function you can iterate trhough all the pointsn, and for each you spawn an object
to randomize the object you can use your meshes variable and use the node to get a random one.
i want them to remain next to eachother but randomly
a way to do this is to generate the points initially all in a grid, and then add a random displacement to each. is cheap and simple and works,
btw imho these random placement code usually ends up being more work than you imagine, and give less than spectacular results.
here’s a thread of someone creating a grid Creating a Hex Grid with Transforms Stored for later reference - #3 by Solevade
this is a random video i found, that i havent watched (though i be spawning components in your case) https://www.youtube.com/watch?v=6Y4GXqlytd0
to move them up/down probably youd need to create a bp and animate it there.