How to change mesh depending on neighbouring grid cell?


I’m currently learning about grid cells in UE4, and came across a small problem.
I’ve got all the logic down, but looking at my logic, the entire process wouldn’t be very optimized. In this pricture below u can see 2 static meshes.

What i want to realize is when a neighbouring cell is of the same type, it connects seamlessy together. This takes into account where the connection is, and it’s rotation. In addition, the round hill from picture 1 would be set to invisible and the other mesh would be set visible. (it all takes place in a single blueprint)

An example of this logic would be (for the situation above). I use 3 XOR gates to narrow the neighbours down from 4 to 1 (a XOR gate has only 2 inputs, but i need to check if it has a North, East, South or West Neighbour. With the XOR gate, i can make sure that there is only 1 connection present before it comes back as true)
In addition, when it returns as true, I adjust the rotation so that it connects seamlessly.

The picture above also shows that it needs to keep the other gridcells in a 3x3 radius also in mind.

So the problem here is that it isn’t very optimized, and I believe that it can be scripted better. Another problem could also be that because every grid cell is a different mesh, you could see that the material doesn’t seamlessly keeps going from grid to grid.

Thanks in advance!