Checking for overlapping actors while ignoring actors that are adjacent

I’m trying to make a build system that allows the player to place objects on a grid. The player is shown if his current placement position is valid based on whether the object that would be placed would overlap with another object. Checking for overlap is currently done like this:

/* actors that overlap */
TArray<AActor*> actors;

/* mesh is a preview of the placed object that is at the placement location */
mesh->GetOverlappingActors(actors);

if (actors.Num() > 0)
{
	/* we have overlap, so change material of preview mesh, etc*/
}

Now this works well most of the time. However, when both objects have the same size as a cell of the grid and you try to place the objects right next to eachother, overlap is detected as well and the placement is considered invalid:

Currently I’m fixing this by setting the scale of the preview actor to 0.98,0.98,0.98 but this probably won’t work well for different mesh sizes or shapes. I would like to know if there is a better way to handle this.

If it’s locked to a grid you probably don’t even need to use the collision system. Just check if the thing you are placing is in the same grid location.

If that won’t work you can call AddIgnoredActor to your collision params (or in the blueprint there’s a pin for it I think) and it will ignore any actors you pass in, so just pass in the adjacent ones. But then you’ll still have to pretty much do what I mentioned first anyway as you constantly add/remove adjacent actors from that check based off their grid position. A better way would probably be to have the actual mesh be slightly bigger than the collision mesh that you’re using for the overlap.

I’d probably still go with the first way though since it’s just a simple check against your indices instead of any sort of complex volume checking.

Thanks for your answer mrooney. The objects are not really locked to a grid but instead it’s just a tool that allows you to allign objects more easily. The cell size can be varied to allow more or less precise placement. The cell size could have a minimum size so that objects are always placed on a grid, but in that case you’d still have to figure out what cells a collision mesh in occupying.

If the actual mesh should be sligtly bigger, I guess you’d want to scale the actual mesh so thath the “border” between the actual mesh and the collision mesh that is always the same size, but how you calculate the scale in that case?