For this I would add to the yellow cube 4 booleans (UP, RIGHT, DOWN, LEFT) and leave them on false as default. I don't know what the blue paths are called, but I'll just call them 'Blue' in this example.
-At Start of layout
-For Each 'cube'
--'YellowCube' overlap 'Blue' at offset Y= -2
---'YellowCube.UP' = True
--'YellowCube' overlap 'Blue' at offset Y= 2
---'YellowCube.DOWN' = True
--'YellowCube' overlap 'Blue' at offset x= -2
---'YellowCube.LEFT' = True
--'YellowCube' overlap 'Blue' at offset Y= 2
---'YellowCube.RIGHT' = True
Then whenever you make it to a yellow cube you just check its booleans. Hope it makes sense.
**Edit** You might need to adjust the offset numbers.