You want to check if each object has another one close by? I did this recently by adding each object to an array, like this:
Start of layout
+ For each object
-> Set value at int(object.x/32)*32, int(object.y/32)*32 to 1
Then you loop through each array element and check if the position above, below, etc equals 1, that means there's an object immediately near it
It was quite difficult to work with it, you will probably need to save the UID of the object to a similar array to use it later... unfortunately I don't have the project anymore so I'm not entirely sure how I did it