RTS Grid system - Placing objects - Check for overlap


so i got a small RTS project. I have a grid building system, which is 100x100 units. My building (only got one) is 200x200 units, with the pivot in the center. So, if you place a building, it’s gonna snap to position 0,0 or 0,100 or 100,100 etc. depending on where the mouse is. So far - so good.

Now, how can i check if the building i want to place, is coliding/overlapping with an other bulding? I Tried using Begin- and Endoverlap, which doesnt work, because the building are also overlapping if they are just next to each other.

Sorry for the bad formulation, i don’t really know how to explain my problem better.


Here are two ways to do this:

(1) The way you are doing it - On your building blueprint, attach a box collision volume that is 25% smaller than your building. Use that for overlap tests (you can make an extra collision channel for just that type if you are worried about performance).

(2) This is another way I’d consider handling it (it may help in the future with performance): create an array of ints, actor refs, or structures 10,000 long. Create a function which returns an index from (x,y) as 100*x+y. Create a function setGridCell(x,y) which sets a location in the array, and GetGridCell(x,y) which gets a location from the array. Now before you place you can query all 4 grid cells to see if anything is there. If there isn’t, you can set the grid cells to either a flag (true or false), the actor ref, or a structure that you can put additional data in.

Let me know if that works for you!

Hey, thanks for the answer. I now used the first way. Kind of.

I have a UI-Button. If i click him, a ghost of the building is spawned (basically the same mesh with green material^^). I just reduced the size of the ghost from 1 to 0.995. This works quite good, however im thinking about using you second solution. Thank you anyway!