Here’s a tutorial on getting a location on the ground from cursor location:
With a similar approach, you can make your line trace detect objects by splitting it’s out hits pin and getting the hit actor. You can divide your map into grids and make your line trace only detect those individual squares rather than things on them by using a custom trace channel for them. And here’s a tutorial on custom trace channels:
You can then use nodes like Spawn Actor and Destroy Actor to add / remove things on your grids.
Hope these help!