Snap to Z/ drag and drop game

Hi there, I did a game setup following this example Blueprint Actor Setup | Unreal Engine Documentation
And I made a aimple grid like this:

I could make the box that I drag with the mouse to snap in some locations, but I need some help:

How do I make another box, snap to Z when coliding with other boxes already on my grid?

Any link with related question or tutorial will be of great help. Thanks

If I understand well your needs, than you simply have to set a constrain plain to your box…
Go to actor details, Physics, set constrain to XYPlane, this way it will not have any motion on Z, while still can be a physical dynamic object with collisions.

Is like making a 2D gameplay, but in your case with 3D objects.

I don’t think you understood me well, I need a way to snap to Z when the object I’m dragging encounter another box, like to stack them.

Well, would be better to see the example graphical, but if you only want that the second box get the Z value of the first one. Just do that with GetActorLocation from first actor then SetActorLocation to second actor, preserving XY and seting only Z.
If you want the snap occurs before the boxes make a physical collision then create a non-visible collision bigger sphere attached to the box to know when they are near anough to trigger the snap code.

not only the second box, any box that is spawned to have this atribute