Dynamically placing piping/conduit during runtime

This is a hard one (IMHO).

I need a way to let the player place a pipe/conduit between 2 points in the game scene. The 2 points don’t necessarily have to be on the same y value (so navmeshagent is out…). The trick is that the pipe/conduit has to avoid any obstacles between the 2 points, and the obstacles are not static (they are placed by the player, but they do have colliders). To make things a little simpler the pipe should only be able to travel at 90 degree angles in every direction.

One idea I had about how to make this happen was to use raycasts from the pipe/conduit end to see which way is clear to go in and try to find the shortest path to the second point. The problem with that is obviously efficiency, considering that for each stop I would have to cast 1-4 rays and see the results. So I was hoping there would be a simpler (or at least a more efficient) way.

EDIT: I should mention that the all the conduits are made from 2 pieces: a straight piece and an elbow piece (90 degrees).

If the pipes and obstacles are all bound to a grid-like structure, then you could just keep a two-dimensional array representing the grid, with each int value being 0 for empty and 1 for filled(obstacle). Instead of RayCasts, you could then just check for obstacles by checking surrounding spaces of any given position in the array.